Game Development Community

Angle Detection

by John Klotz · in Torque Game Builder · 07/14/2006 (9:03 am) · 5 replies

Is there a way to determine at what angle a specific object is traveling. For example, a gett2dangle function or something like that?

Thanks for any and all help

#1
07/14/2006 (10:53 am)
You can pass the x,y velocity from getLinearVelocity into the arcTanget (mATan(%x, %y) in TS) to get the angle in radians, which you can convert to a degree angle with mRadToDeg(%rad). Though I think you need to do a little tweaking to get it to return proper values all the time, since there's no aTan2 function by default for TS. I wrote a hacky one in script that seems to be working okay for what I need. I'm horrible at math though, so someone probably knows this better than me.
#2
07/15/2006 (5:49 am)
MAtan(%x, %y) is atan2 in TS. You can confirm that in the source if you please... I already did. It does return proper values, just different from the way mathematicians use angles. In math, 0 degrees points to the right, and positive angles go counter-clockwise. In TS, 0 degrees points up and positive angles go clockwise.
#3
07/16/2006 (1:46 pm)
%angle = getWord( %object.getLinearVelocityPolar(), 0 );
#4
07/16/2006 (6:24 pm)
Chris, that just gets the x component of the the linear velocity. That's not an angle.
#5
07/16/2006 (6:40 pm)
Really? It's getlinearVelocityPolar... the docs say:

Quote:getLinearVelocityPolar()
Purpose
Gets the speed and direction at which the object is moving.
Return Value - List
The speed of the object as a float and the direction of the object as an angle in the form "angle
speed".

I've always used this to get the angle.