• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Landing on a certain side

Jeff

Member
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