Game Development Community

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

#1
06/16/2005 (12:19 pm)
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;
}
#2
06/16/2005 (12:25 pm)
Thank you Matt...

- Jesse
#3
06/16/2005 (2:36 pm)
Or just use the engine-side console method angleBetween2D(). It's in the T2D reference pdf.
#4
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?