流畅的相机以第三人称围绕玩家旋转
Smooth camera rotate around the player in 3rd person
我在平滑旋转方面遇到问题,我正在尝试制作一款像 Temple 运行 中那样具有旋转系统的游戏。我不知道如何通过 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);
}
}
}
我建议对相机的变换执行 Transform.RotateAround(),使用玩家的游戏对象作为轴。
示例:
//in camera-code
transform.RotateAround(player.transform.position, Vector3.up, 45f);
希望对您有所帮助!
编辑:
此外,您还可以使用Mathf.LerpAngle代替固定值作为第三个参数,以确保更平滑的结果。
我在平滑旋转方面遇到问题,我正在尝试制作一款像 Temple 运行 中那样具有旋转系统的游戏。我不知道如何通过 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);
}
}
}
我建议对相机的变换执行 Transform.RotateAround(),使用玩家的游戏对象作为轴。
示例:
//in camera-code
transform.RotateAround(player.transform.position, Vector3.up, 45f);
希望对您有所帮助!
编辑: 此外,您还可以使用Mathf.LerpAngle代替固定值作为第三个参数,以确保更平滑的结果。