I'm trying to make the player in my game face the mouse, and I think it would be better to use the angle expression rather than 32 directions. But what ever I try doesn't work. Can anyone help?
-start of frame
+set fixed object to (your character)
-always
+set angle of (your character) to FixedAngle( "Advanced Math object", XMouse, YMouse)
Edited by Cecilectomy
n/a
Assault Andy Administrator
I make other people create vaporware
Registered 29/07/2002
Points 5686
27th February, 2010 at 03:59:51 -
I prefer to use the Advanced Direction Object, as it doesn't require a fixed object:
Always: Set angle of Active to Direction( "Advanced Direction Object", X( "Active" ),Y( "Active" ),Xmouse,Ymouse)
You could use ATan2(). It finds the angle between two objects, using this form: ATan2(X("Active 2")-X("Active"),Y("Active 2")-Y("Active")). You might have to add or subtract 90 to make it the correct angle, I never could remember which and it always seemed to be different. You could also use the Advanced Direction object (or Advanced Math, I've not used either so I wouldn't know which) to do the math. From there it's just a matter of setting the angle to the result of that formula.
If you do it in the order I wrote it (ie. "yA-yB, xB-xA") you don't need to add/subtract 90 degrees or whatever.
It's just one of the weird side-effects of the Y axis being inverted.
I don't thing ATan2 is a "proper" trigonometric function exactly - it's kind of an algorithm that computer programmers invented. It certainly never got a mention in maths classes when I was at school.
ATan isn't really a "proper" method, only makes computing easier. If you use a "proper" Tan, it gets the bottom quadrant upside down, and ATan gets for use in practical applications (like this). Yeah, they should be teaching you the problems of a normal Tan in school.
What Sketchy's formula does is that it just calculates the angle, since Tan uses the ratio between the Y and X to get you the angle.
Should cover Cos and Sin, but I left out Tan, lol. It's a bit better than what I learned in school; I find that a lot of my teachers can teach what it is but have no idea how to use it :/ I'll add a section on Tan if you want
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.