Unity3D中的第三人称相机追随者



我尝试制作一个第三人称摄像机,它跟随我的玩家,摄像机应该旋转,但不是玩家,如果我使用控制器的右模拟摇杆。我遵循这个教程

我代码:

void adjustCameraToPlayer() 
{
    Quaternion rotation = Quaternion.identity;
    if (Input.GetAxis("RightStickX") != 0f)
    {
        float horizontal = Input.GetAxis("RightStickX") / 100f;
        transform.Rotate(0, horizontal, 0);
        float desiredAngle = transform.eulerAngles.y;
        rotation = Quaternion.Euler(0, desiredAngle, 0);
    }
    transform.position = player.transform.position-(rotation * offset);
    transform.LookAt(player.transform);
}

我的问题是,相机旋转的方式太快,我试图改变水平值的红利,但它没有帮助。

这就是为什么你总是应该将deltaTime合并到每帧发生的转换操作中。这样你就不用每一帧都旋转它的大小,而是随时间旋转。此外,您还应该合并一个可以实时操作的speed变量,以便您可以按自己的意愿调整它:

public float speed = 5f;
void adjustCameraToPlayer() 
{
    Quaternion rotation = Quaternion.identity;
    if (Input.GetAxis("RightStickX") != 0f)
    {
        float horizontal = Input.GetAxis("RightStickX");
        transform.Rotate(Vector3.up * horizontal * speed * Time.deltaTime);
        float desiredAngle = transform.eulerAngles.y;
        rotation = Quaternion.Euler(0, desiredAngle, 0);
    }
    transform.position = player.transform.position-(rotation * offset);
    transform.LookAt(player.transform);
}

最新更新