• 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!

Android flick object to a direction, but stay in 4 direction rules

anselm

Member
I want a character to move using flick gestures, but i want it to just move in 0,90,180,270 directions, and not to go diagonally.

HELP PLEASE
 

Roderick

Member
What have you tried so far?

If you're already reading the direction and getting a result in degrees, take that result and divide by 90, and then round() to the nearest integer. This will give you 0, 1, 2, 3 or 4. Then multiply by 90 to get 0, 90, 180, 270 or 360. If your code can't handle a result of 0 or 360, change it to be whichever one your code is ok with.
 
Top