Hi I am currently making a first person controller. Everything looks smooth when i walk or look around but only when i do one at the time. When i move and look around everything jitters.
Here is the code below:
CameraMouseFirstPerson.cs
public class CameraMouseFirstPerson : MonoBehaviour
{
public float moveSpeedX = 10;
public float moveSpeedY = 10;
void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
float pitch = Input.GetAxis("Mouse Y") * -moveSpeedY;
float yaw = Input.GetAxis("Mouse X") * moveSpeedX;
transform.Rotate(0, yaw, 0, Space.World);
transform.Rotate(pitch, 0, 0, Space.Self);
}
}
PlayerWalker.cs
public class PlayerWalker : MonoBehaviour
{
[SerializeField]
private float moveSpeed = 10;
[SerializeField]
private float moveCap = 10;
[SerializeField]
private Rigidbody rigidbody = null;
void Update()
{
float deltaForward = Input.GetAxis("Vertical") * moveSpeed;
float deltaSide = Input.GetAxis("Horizontal") * moveSpeed;
Vector3 dir = (transform.rotation * Vector3.forward * deltaForward) + (transform.rotation * Vector3.right * deltaSide);
dir.y = 0;
if(rigidbody.velocity.magnitude < moveCap)
rigidbody.velocity += dir * Time.deltaTime;
}
}
Player entity
Any help would be appreciated