Click here to Skip to main content
15,867,568 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:

C#
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.
Posted
Updated 6-May-13 23:43pm
v4
Comments
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

X -> Y = ~135.

1 solution

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);
 
Share this answer
 

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