Getting a t2dShape3D model to rotateto...?
by David Taylor · in Torque Game Builder · 12/10/2006 (10:22 pm) · 5 replies
I want to basically call something in the vein of RotateTo() on my t2dShape3D model. I can set it on an automatic rotation by calling the %obj.setShapeAngularVelocity(%x, %y, %z) function, but I want it to stop once it reaches (0, 0, 0). I was hoping to use something like RotateTo() to do this.
Any suggestions on how to go about this? The object is only rotating on the Y axis.
Any suggestions on how to go about this? The object is only rotating on the Y axis.
About the author
#2
But thanks - great idea. I just don't know how to execute it.
12/11/2006 (4:28 pm)
Yep, I wouldn't have a clue where to start with that, lol.But thanks - great idea. I just don't know how to execute it.
#3
%this = your t2dShape3D object
%targetY = the rotation you want your shape to be at in degrees (-180 - 180)
%speed = how fast you want it to rotate (a negative value will rotate in the opposite direction)
I did some basic testing and it seemed to work fine. Just let me know if something doesn't seem right or if you want me to change some of its functionality.
^_^
EDIT: Fixed an error and added comments so it's easier to follow.
12/11/2006 (7:59 pm)
Ok, so I was really bored and decided to try and write this function for you! :)function rotateTo( %this, %targetY, %speed ) {
// Get the current Y Rotation and convert it to Degrees
%currentY = mRadToDeg( getWord( %this.getShapeRotation(), 2 ) );
// Set the angular velocity on the y-axis to %speed
%this.setShapeAngularVelocity( 0, %speed, 0 );
// While rotating, %currentY will never be exactly the same as %targetY,
// but it does get very close (within 1 degree). So we take the absolute
// value of the %targetY - %currentY and check to see if it's greater
// or less than the value of 1
if( mAbs( %targetY - %currentY ) >= 1 ) {
// If it is greater than or equal to 1, then we schedule this function to
// run again with the same parameters
schedule( 20, 0, "rotateTo", %this, %targetY, %speed );
} else {
// If it is less than 1, then stop rotation and set the y-axis rotation
// to %targetY, which rotates it that last little bit so they are now equal
%this.setShapeAngularVelocity( 0, 0, 0 );
%this.setShapeRotation( 0, %targetY, 0 );
}
}%this = your t2dShape3D object
%targetY = the rotation you want your shape to be at in degrees (-180 - 180)
%speed = how fast you want it to rotate (a negative value will rotate in the opposite direction)
I did some basic testing and it seemed to work fine. Just let me know if something doesn't seem right or if you want me to change some of its functionality.
^_^
EDIT: Fixed an error and added comments so it's easier to follow.
#4
12/12/2006 (5:23 pm)
Awesome! That does the trick! Thanks! :)
#5
i.e. I can rotate it using setShapeAngularVelocity() but getShapeRotation() still returns the starting rotation setting. Not the current one.
EDIT: solution is to use getShapeAngularRotation() ...
10/15/2011 (11:08 pm)
getShapeRotation() returns the same values, after the object is created ... i.e. I can rotate it using setShapeAngularVelocity() but getShapeRotation() still returns the starting rotation setting. Not the current one.
EDIT: solution is to use getShapeAngularRotation() ...
Torque Owner Phillip "Renolc" Gibson
I'm speaking from inexperience though. I have yet to use t2dShape3D objects. :)