0

I'm working on a 2D BMX game with flips and spins and I'd like to make it so if the bike lands at the wrong angle it'll crash and restart at the checkpoint. For testing purposes I've tried to make it so the character will restart at the nearest checkpoint when it hits a certain angle. The relevant script is

public float Landing;
void Update()
{
    Landing = transform.rotation.eulerAngles.y;
}
if ( Landing == 100)
{
reset
} 

I've also tried

If(transform.rotation.eulerAngles.y == 100) 

but that's not working either. Unity is showing no errors in my script.

Paul
  • 7
  • 1
  • So what errors does Unity check for? Or what values are being evaluated at each step in your code? Is what you test what you expect to test? – Solar Mike Feb 26 '23 at 17:00
  • It's not reacting in anyway. It's almost like the If statement hasn't even been typed in. I can see in the Inspector that the float Landing angle is being read accurately but the character is not reseting when it get to 100. The level plays the same as if I haven't changed anything. – Paul Feb 26 '23 at 17:27

1 Answers1

0

You probably shouldn't be trying to catch rotating angles in specific integer values. No one can guarantee your values will be rounded, unless you do rounding to integer. Instead use ranges. If angle > 100, player falls and so on. At the end of the day, you don't care for a specific angle but anything beyond that.

NPatch
  • 66
  • 6