提问人:notPatern 提问时间:5/3/2023 最后编辑:notPatern 更新时间:5/3/2023 访问量:179
unity3D 中摄像机上的抖动问题
Jitter Issue on a Camera in unity3D
问:
当我在关卡中移动玩家时,我的相机出现了问题。 我的意思是: 使用鼠标环顾四周时,游戏运行流畅,但是一旦我开始使用 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
答: 暂无答案
评论
MoveInputs
FixedUpdate
FixedUpdate