Game Development Community

rotateto (pointing one object to another)

by Gavin Beard · in Torque Game Builder · 02/19/2009 (3:19 pm) · 3 replies

hi all

I have two objects within a simple scene, One is static, the other moves with user input. I've trying to get OBJECT1 (the static object) to point towards OBJECT2 (the moving object) in real time as OBJECT2 moves.

I thought maybe .rotateTo() was what i was looking for, but it seem to do a massive amount. i'm using code:

OBJECT1.rotateTo(OBJECT2.position,60);

but as i was the movement is very sporadic and never seems to point anywhere near the other object?

Is there anything i'm missing?

thanks

#1
02/19/2009 (5:01 pm)
You need to rotate to a degree, not a position.

Here's a snippet I found that does the math pretty elegantly.

//1 get a vector between 2 objects
%vector = t2dVectorSub(%targetObject.position, %this.position);
//convert to degrees
%targetRotation = mRadToDeg(mAtan(%vector.y, %vector.x)) + 90;
//rotate to vector
%this.rotateTo(%targetRotation, %rotationSpeed);
#2
02/20/2009 (3:54 am)
I'll give this a try and see how it goes, will let u know. Many thanks
#3
06/06/2009 (3:45 pm)
For posterity, there is a behavior to do this which can be used as an example or directly.