Unity中Cinemachine虚拟相机速度异常问题求助
Unity新输入系统搭配Cinemachine相机速度异常问题
我在Unity项目中使用新输入系统,同时搭配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 Value Gain,Cinemachine Input Provider绑定新输入系统的配置
- Input Actions设置截图1:展示Move动作的输入绑定详情
- Input Actions设置截图2:展示Look动作的输入绑定详情
内容的提问来源于stack exchange,提问作者laflare247
相关产品推荐
相关产品推荐

