Click here to Skip to main content
15,399,440 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone!

I am trying to add angles to my game. However,
when I add these angles, they just don't work:

if (e.State.X < Cradle.GraphicsManager.PreferredBackBufferWidth / 2)
    this.Player.EntityHeadAngle = (int)Math.Atan2(e.State.X - Cradle.GraphicsManager.PreferredBackBufferWidth / 2, e.State.Y);

e.State.X = Mouse X,Y
Cradle.GraphicsManager.PreferredBackBufferWidth = Width, Height of the form. 

Also, there should also be an else statement, but I wasn't sure how to do this one yet, so I couldn't go to the next one. Any ideas why this doesn't work?

Edit: The problem is when I look down it faces up, and when I look down it doesn't do anything.
Edit:Edit: I'm trying to make a head turn, but I flip the Texture when the else statement arrives.
Updated 6-May-13 23:43pm
CPallini 7-May-13 5:44am
It is not clear (at least to me) what are you trying to accomplish. Could you please state it more clearly?
Deviant Sapphire 7-May-13 5:50am
First of all, please stop unneccsarily editing my post. Next, I am trying to accomplish getting the angles by points. For now, the angle should be calculated from the middle of the form, to a point on the screen. Unfortunatly, whenever I do this I seem to be getting odd results.
Deviant Sapphire 7-May-13 5:54am
"Uneccsarily editing my posts" Well grammar failed quite hard there. Oh, and that was pointed at the guy, not you, sorry. :L
CPallini 7-May-13 6:23am
Oh don't worry.
You need at least three points if want to compute an angle.
Deviant Sapphire 7-May-13 6:26am
No you do not? :L



X -> Y = ~135.
CPallini 7-May-13 6:47am
I don't get you, please elaborate.
Matt T Heffron 7-May-13 13:31pm
Yes, you do need 3 points!
In this case you are just assuming one of them, the "implied" point directly "up" from your X.
Keith Barrow 14-Jun-13 8:22am
I wish I could upvote this.
Deviant Sapphire 7-May-13 6:42am
I got it fixed.
Deviant Sapphire 7-May-13 6:35am
Okay, so I fixed the first line. It was because I forgot to do the Y.
But still the head is turning the wrong way?

this.Player.EntityHeadAngle = (float)(Math.PI / 4 - (Math.Atan2(e.State.X - Cradle.GraphicsManager.PreferredBackBufferWidth / 2, e.State.Y - Cradle.GraphicsManager.PreferredBackBufferHeight)));

1 solution


Vector2 dPos = new Vector2(e.State.X - Cradle.GraphicsManager.PreferredBackBufferWidth / 2, e.State.Y - Cradle.GraphicsManager.PreferredBackBufferHeight / 2);
this.Player.EntityHeadAngle = (float)Math.Atan2(dPos.Y, dPos.X);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900