Hi. I am fairly new to using Unity for 2D games. I am currently making a platformer and when the player is moving the sprite will occasionally “shake like crazy”. This is the script I’m using in Fixed Update.
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
float xSpeed = Input.GetAxis("Horizontal") * 2.0f;
anim.SetFloat("Speed", Mathf.Abs(xSpeed));
this.rigidbody2D.AddForce(new Vector2(xSpeed * MoveFactor, 0f));
// If the input is moving the player right and the player is facing left...
if (h > 0 && !facingRight)
// ... flip the player.
Flip();
// Otherwise if the input is moving the player left and the player is facing right...
else if (h < 0 && facingRight)
// ... flip the player.
Flip();
}
Do you think you could help me fix it?
Thank you soooo much! It stopped the player from shaking and made the speed consistent.
– Supah_Develepor