I get an issue with my camera when I move my player around in a level. What I mean by this is: When looking around using the mouse, the game runs smoothly, however once I start to use WASD to move my player around, the camera jitters.
Here is a video of just that (might be hard to percieve)
My camera script and the the script that makes the camera follow the player are two different scripts and the issue only occurs when the camera has to follow the player, I thus assumed that the issue was from the MovePlayerCam script which goes as follows:
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
}
}
I have another project of mine, with the same MovePlayerCam script, in which the issue doesn't occur. However, in this project I am using the old unity input system to move my player around. In the project I'm having the issue with, I am trying to learn how to use the new Input system, I might've broken something there so here is my player movement script as well:
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);
}
}
}
To Fix this, I tried putting the MovePlayerCam script in lateUpdate, in a FixedUpdate and none worked. I still get the camera jitter when moving around. So please help lmao