Hello my game has a tile based map and the character moves around in 4 directions (Up,Down,Left,Right) what id like to do is click or touch the screen and it will move in one of these directions.

If im trying to imagine it picture the screen as a square and spliting it in the shape of a cross so a touch event happens in each of the four segments it will move in that direction.

So i figured working out an angle in degrees from the center of the screen to the touch position is the way to go but i was getting weird results and i had trouble writing good IF statments for the angles.

Ive tried a few things but i honestly think i was just using them wrong.

What i need is what is the best way to work out this angle and how to use the if statment for the UP direction as it will be between 315 and 45 i would learn from this for the others.

Thank you and if any more info is needed just say.

So, imagine a square, with diagonal lines from corner to corner. This divides the square into 4 pieces, call them North, East, South and West. They are each triangle shapes, with a long edge along the sides of the square. If you think about only the East part, then the lines it has are at 45 degrees and -45 degrees. I think you want to know if the user has clicked/touched in this area. Note that in this area the x coordinate is positive, and the y coordinate might be positive or negative. (This assumes the centre of the screen is at 0,0. You might need to do some subtraction of half the screen width and height to compute these origin relative values.) Note also, that you’ve only clicked in this area if the x coordinate is greater than the absolute value of the y coordinate. If the y coordinate is positive, and greater than the x coord, then you’ve touched north. If the y coordinate is negative, and the absolute value is greater than the x coord, then you’ve clicked in south. Then repeat these tests for x negative. You’ll end up with hits in West, or more hits in North or South.

(What I mean is, you don’t need the angle at all.)