So I was attempting to make a topdown space ship shooter of sorts, mostly to get a hang of Unity.
My issue is that the player character is stuttering a lot. The camera has a script to follow the player but ut happens even when i disabled that script to see where the issue lied. The hierarchy of the player char is PlayerEmpty>Cube with the player movement script and rigidbody.
The code is as follows;
[Header("Player Movement")]
[SerializeField] float movementSpeed = 10f;
[SerializeField] float turningSpeed = 4f;
[SerializeField] float gravityModifier;
private Rigidbody playerRb;
private Physics physics;
private void Start()
{
playerRb = GetComponent<Rigidbody>();
Physics.gravity = Vector3.zero; // Disables gravity
playerRb.interpolation = RigidbodyInterpolation.Interpolate;
}
private void FixedUpdate()
{
PlayerMotion();
}
void PlayerMotion()
{
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
Vector3 moveDirection = new Vector3(horizontalInput, 0f, verticalInput).normalized;
if (moveDirection.magnitude > 0.1f)
{
// Gets angle of rotation that should take place
float targetAngle = Mathf.Atan2(moveDirection.x, moveDirection.z) * Mathf.Rad2Deg;
// Lerps the player between current and target angle smoothly
float smoothAngle = Mathf.LerpAngle(transform.eulerAngles.y, targetAngle, 1 - Mathf.Exp(-turningSpeed * Time.deltaTime));
//Applies smoothed rotation to player
transform.rotation = Quaternion.Euler(0f, smoothAngle, 0);
//Allows Player movement
playerRb.MovePosition(transform.position + movementSpeed * Time.deltaTime * moveDirection);
}
}
} ```