我正在尝试让摄像机围绕玩家旋转,以便玩家始终位于屏幕中间。
我试过使用这个Slerp()功能。
using UnityEngine;
using System.Collections;
public class rotate : MonoBehaviour
{
public Transform target;
public float Speed = 1f;
public Camera cam;
public Vector3 offset;
void Update()
{
Vector3 direction = (target.position - cam.transform.position).normalized;
Quaternion lookrotation = target.rotation;
Quaternion playerrotation = target.rotation;
playerrotation.y = target.rotation.y;
playerrotation.x = 0f;
playerrotation.z = 0f;
lookrotation.x = transform.rotation.x;
lookrotation.z = transform.rotation.z;
//lookrotation.y = transform.rotation.y;
offset.x = -target.rotation.x * Mathf.PI;
transform.rotation = Quaternion.Slerp(transform.rotation, playerrotation, Time.deltaTime * Speed);
transform.position = Vector3.Slerp(transform.position, target.position + offset, Time.deltaTime * 10000);
}
}
它有效,但播放器不在屏幕中间。
慕哥9229398
相关分类