unity3D 中摄像机上的抖动问题

Jitter Issue on a Camera in unity3D

提问人:notPatern 提问时间:5/3/2023 最后编辑:notPatern 更新时间:5/3/2023 访问量:179

问:

当我在关卡中移动玩家时,我的相机出现了问题。 我的意思是: 使用鼠标环顾四周时,游戏运行流畅,但是一旦我开始使用 WASD 移动我的播放器,相机就会抖动。

这是一个视频(可能很难理解)

我的相机脚本和使相机跟随玩家的脚本是两个不同的脚本,只有当相机必须跟随玩家时才会出现问题,因此我假设问题来自 MovePlayerCam 脚本,如下所示:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovePlayerCam : MonoBehaviour
{
    public Transform CamHolder;

    void Update()
    {
        transform.position = CamHolder.position;
        // camHolder is an empty GameObject that is contained by a player Parent Object that has the player movement script
    }
}

我有我的另一个项目,使用相同的 MovePlayerCam 脚本,其中没有出现问题。但是,在这个项目中,我使用旧的 unity 输入系统来移动我的播放器。在我遇到问题的项目中,我正在尝试学习如何使用新的输入系统,我可能在那里破坏了一些东西,所以这里也是我的玩家移动脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine;

public class BaseMovement : MonoBehaviour
{
    [Header("ref")]
    Rigidbody rb;
    public Transform orientation;
    public PlayerInputs playerControls;

    [Header("Values")]
    public float moveSpeed;
    public float jumpStrength;
    public float maxMoveSpeed;
    public float airMultiplier;
    public float groundDrag;
    public float airDrag;
    public float crouchDrag;
    public float slideDrag;
    bool grounded;


    Vector3 moveDirection;
    private InputAction move;
    private InputAction vertical;

    private void Awake()
    {
        playerControls = new PlayerInputs();
    }

    private void OnEnable()
    {
        move = playerControls.Player.Move;
        move.Enable();
    }
    private void OnDisable()
    {
        move.Disable();
    }

    void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.drag = groundDrag;
    }

    void Update()
    {
        MoveInputs();
    }

    private void MoveInputs()
    {
        if (rb.velocity.magnitude < maxMoveSpeed)
        {
            moveDirection = orientation.forward * move.ReadValue<Vector2>().y + orientation.right * move.ReadValue<Vector2>().x;
            rb.AddForce(moveDirection.normalized * moveSpeed * airMultiplier, ForceMode.Force);
        }
    }
}

为了解决这个问题,我尝试将 MovePlayerCam 脚本放在 lateUpdate 中,放在 FixedUpdate 中,但没有一个有效。四处走动时,我仍然会感到相机抖动。所以请帮忙lmao

C# unity-game-engine 相机 抖动

评论

2赞 hijinxbassist 5/3/2023
您正在 Update 中进行物理工作。尝试拨打 。MoveInputsFixedUpdate
1赞 hijinxbassist 5/3/2023
您是否也尝试过将相机移动更改为?FixedUpdate
1赞 notPatern 5/3/2023
如帖子中所述,更改更新不起作用
1赞 Jay 5/3/2023
您通过每帧添加一个力来移动相机,这不是一种帧速率独立的方式。您有两种选择,以某种稳定的方式手动指定速度(仅不依赖于帧速率进行修改)。这将失去纯粹的物理模拟。或者通过向每帧的位置移动相机来缓解相机的移动
1赞 Jay 5/3/2023
@rshepp操作正确,延迟更新或定期更新对这个问题没有影响,与执行顺序无关

答: 暂无答案