How to track mouse with a turret?
by Jesse Hall · in Torque Game Builder · 06/16/2005 (12:14 pm) · 5 replies
What would be the best way to go about rotating a tank turret to face a set of crosshairs controlled by the mouse.
Im working through the mouse object tutorials so I am certain I can get the crosshairs and mouse posistion fine but how do i use that to get my rotation angle?
Is there a simple funtion for this?
Of course I could use math and determine that angle between the points but what is the formula? My math is rusty at best! Any links for game math tuts would be appreciated as well.
best regards
Jesse
Im working through the mouse object tutorials so I am certain I can get the crosshairs and mouse posistion fine but how do i use that to get my rotation angle?
Is there a simple funtion for this?
Of course I could use math and determine that angle between the points but what is the formula? My math is rusty at best! Any links for game math tuts would be appreciated as well.
best regards
Jesse
About the author
#3
06/16/2005 (2:36 pm)
Or just use the engine-side console method angleBetween2D(). It's in the T2D reference pdf.
#4
I'm stuck right now at getting the pointer to change to a crosshairs.
I dont want the cross hairs all the time. I have been looking at the various .CS files and can find where it assigns the default pointer anyway though.
Is there some function to get the mouse invis so i can just mount it with an object?
06/17/2005 (12:56 pm)
Thanks for the help guys!!I'm stuck right now at getting the pointer to change to a crosshairs.
I dont want the cross hairs all the time. I have been looking at the various .CS files and can find where it assigns the default pointer anyway though.
Is there some function to get the mouse invis so i can just mount it with an object?
#5
06/18/2005 (1:30 am)
As it happens, everything you need is here: www.garagegames.com/mg/forums/result.thread.php?qt=28399
Torque 3D Owner Matthew Langley
Torque
function angleBetween(%playerPos, %mousePos) { // Seperate Mouse Position %mxpos = getWord(%mousePos,0); %mypos = getWord(%mousePos,1); // Seperate Player Position %px = getWord(%playerPos,0); %py = getWord(%playerPos,1); // Calculate Angle from player to mouse (convert to degrees). %angle = mRadToDeg( mAtan( %mxpos-%px, %py-%mypos ) ); return %angle; }