Game Development Community

What direction is player moving?

by Joel Hargarten · in Technical Issues · 07/21/2005 (7:59 pm) · 2 replies

Hey,
I'm seting up a switch statement in weapon.cs so I can choose which attack animation to play based on the direction I am currently moving. I have everything for that figured out. What I need to know is, how do I tell which direction the player is moving. And I'll have a seperate animation for all directions, so if someone could tell me how to figure this out, it would be great. Thanks.

#1
07/21/2005 (8:39 pm)
Why dont you just put a direction flag in the movement functions in default.bind.cs? you could have a global called direction which is set to a unique value or string when each movement function is called. when the function is called again with 0, you could reset the global variable to verify this.
#2
07/22/2005 (4:12 am)
Sean H- Just because you are pressing forward doesnt mean you are moving forward. It is quite possible you wlil be accelerating in the forward direciton while moving backwards.

Joel - call dump on the player. You will find some useful functions in there. One will be getForwardVector90 which will return the way you are facing. I imagine there is a getVelocity() as well. If the dot product of those two vectors if positive then you aremoving foward. If it's negative you are moving backwards.

Im not sure how to do that in Torque. In the source it is mDot. If you own the source you can make that accessible to the console, if it's not already.