【问题标题】:Strange behaviour of the Cinemachine virtual cameraCinemachine 虚拟相机的奇怪行为
【发布时间】:2022-11-12 16:13:43
【问题描述】:

我在我的统一项目中使用new input system。我也使用Cinemachine。我使用Cinemachine Input Provider 将输入从旧系统更改为新系统。 当我在虚拟相机设置的速度字段中将max speed 更改为Input Value Gain 时(我这样做是因为它是控制相机最舒适的方式)我遇到了一个问题。 我的问题:当我的角色在一段时间后移动时,相机速度会发生变化。如果我开始向相反方向移动,相机速度就会恢复正常。 这与场景中的其他组件无关。我的场景只有平面、立方体、相机和我的角色。

这是我的角色控制代码(忽略移动方向的糟糕计算):

private Rigidbody _rb;

private Vector2 _moveDirection;

private float speed = 5f;

private void Awake()
{
    _rb = GetComponent<Rigidbody>();
    Cursor.lockState = CursorLockMode.Locked;
}

public void OnMove(InputAction.CallbackContext context)
{
    _moveDirection = context.ReadValue<Vector2>();
}

private void FixedUpdate()
{
    Move(_moveDirection);
}

private void Move(Vector3 moveDirection)
{
    float scaledMoveSpeed = speed * Time.deltaTime;

    moveDirection = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z).normalized  * moveDirection.y + new Vector3(Camera.main.transform.right.x, 0, Camera.main.transform.right.z).normalized * moveDirection.x;
    _rb.MovePosition(transform.position + moveDirection * scaledMoveSpeed);
}

这是相机设置和Cinemachine Input Provider的截图:

以及Input Actions 设置的截图:

【问题讨论】:

    标签: c# unity3d unityscript


    【解决方案1】:

    我为那些将面临这个问题的人找到了解决方案!在您的main camera 上,在CinemachineBrain 组件中,将Update MethodSmart Update 更改为Late Update。那应该有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 2010-11-08
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      相关资源
      最近更新 更多