我有顺畅旋转的问题,我试图像Temple Run那样使用旋转系统制作游戏。我不知道如何通过lerp附加平滑旋转,例如偏移。
//Position
public GameObject player;
private Vector3 offSet;
//Rotation
//Quaternion localRotation;
Quaternion leftRotation = Quaternion.Euler(new Vector3 (0, 90, 0));
Quaternion rightRotation = Quaternion.Euler(new Vector3 (0, -90, 0));
Vector3 lRotation = new Vector3(0.0f, -90f, 0.0f);
Vector3 rRotation = new Vector3(0.0f, 90f, 0.0f);
void Start () {
offSet = transform.position - player.transform.position;
}
void Update () {
}
void LateUpdate(){
transform.position = player.transform.position + offSet;
transform.LookAt (player.transform);
if (Input.GetKeyDown (KeyCode.LeftArrow) && GameObject.Find("Player").GetComponent<PlayerMovement>().turn) {
offSet = Quaternion.Euler(lRotation)*offSet;
transform.position = player.transform.position + offSet;
transform.LookAt (player.transform);
} else if (Input.GetKeyDown (KeyCode.RightArrow) && GameObject.Find("Player").GetComponent<PlayerMovement>().turn) {
offSet = Quaternion.Euler(rRotation)*offSet;
transform.position = player.transform.position + offSet;
transform.LookAt (player.transform);
}
}
}
答案 0 :(得分:0)
我建议在相机的变换上执行Transform.RotateAround(),使用玩家的游戏对象作为轴。
示例:
//in camera-code
transform.RotateAround(player.transform.position, Vector3.up, 45f);
我希望有所帮助!
修改强> 此外,您还可以使用Mathf.LerpAngle而不是固定值作为第三个参数,以确保更顺畅的结果。