Home > Back-end >  weapon is supposed to flip after higher than 90 degress / lower than -90 degrees so it isnt upside d
weapon is supposed to flip after higher than 90 degress / lower than -90 degrees so it isnt upside d

Time:12-26

The weapon flips if the angle is above 90 degrees like intended but doesnt flip if the angle is bellow -90 degrees. For some reason it does flip on the Y axis if the angle is 0 or 180 degrees.

if (Weapon.transform.eulerAngles.z < 90 && Weapon.transform.eulerAngles.z > -90)
{
    Weapon.GetComponent<SpriteRenderer>().flipY = false;
}
else
{
    Weapon.GetComponent<SpriteRenderer>().flipY = true;
}

visualization

the weapon follows my mouse with this code:

Vector2 mouseScreenPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

Vector2 direction = (mouseScreenPosition - (Vector2)transform.position).normalized;

transform.right = direction;

i dont have any issues with the weapon pointing towards my mouse.

I already tried it with different angles but only the positive one flipped the weapon and 0 degrees. I appreciate every answer. Thank you for your time.

CodePudding user response:

Fixed it with this:

if ((Weapon.transform.eulerAngles.z < 90 && Weapon.transform.eulerAngles.z >= 0) || (Weapon.transform.eulerAngles.z > 270 && Weapon.transform.eulerAngles.z <= 360))
  • Related