So we’re basically making a 2D shooter type of game in Unity with a friend from school. I’m trying to make my character shoot in both directions which I’ve achieved with rotating the character on the y axis by 180 degrees on pressing the movement keys. The problem is, everytime I press the movement key (A and D), the character rotates to the wrong side if I press the direction key multiple times.
void Update()
{
if (Input.GetKeyUp(KeyCode.A))
{
transform.Rotate(0f, 180f, 0f);
}
if (Input.GetKeyUp(KeyCode.D))
{
transform.Rotate(0f, 180f, 0f);
}
isTouchingGround = Physics2D.OverlapCircle(groundCheckPoint.position, groundCheckRadius, groundLayer);
movement = Input.GetAxis("Horizontal");
if (movement > 0f)
{
rigidBody.velocity = new Vector2(movement * speed, rigidBody.velocity.y);
}
else if (movement < 0f)
{
rigidBody.velocity = new Vector2(movement * speed, rigidBody.velocity.y);
}
else
{
rigidBody.velocity = new Vector2(0, rigidBody.velocity.y);
}
if (Input.GetButtonDown("Jump") && isTouchingGround) {
rigidBody.velocity = new Vector2(rigidBody.velocity.x, jumpspeed);
}
playerAnimation.SetFloat("Speed", Mathf.Abs(rigidBody.velocity.x));
playerAnimation.SetBool("OnGround", isTouchingGround);
We are barely beginners to programming so I would appreciate some help