• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Landing on a certain side

J

Jeff

Guest
Hi
I was creating a simple game where a square will jump and rotate. The object would not always land on a side and it would sometime land on a corner. I was wondering if there was a way so that the square always lands on one of its sides and not on a corner?
 

obscene

Member
You probably want to just "snap" it to a side when it lands, setting it's angle to whichever is closer of 0, 90, 180 or 270 ( or if it looks the same either way, just 0 ).

You can do this by...
1 Divide the angle by 90. This will give you a value between 0 and 3.
2 Floor it so you get exactly 0,1,2 or 3.
3 Multiply it by 90 again.
 
Top