Help: Trying to rotate objects
by Marvin Hawkins · in General Discussion · 01/29/2009 (8:47 am) · 6 replies
Is it possible to rotate objects that are an interior extension? I basically want to be able to rotate entities.
So how can I rotate objects in torque in programming? I know this sounds a bit noobish but if you can point me to a tutorial that'd be great. Thanks in advance.
So how can I rotate objects in torque in programming? I know this sounds a bit noobish but if you can point me to a tutorial that'd be great. Thanks in advance.
#2
01/30/2009 (10:18 pm)
well i think all your trying to do is rotate a object. you don't need no code for that the engine comes with rotation. to rotate a object in the editor just click the object and then press and hold alt key then you can rotate the object just like you would to move the object. to change the speed of the rotation click on edit then world editor settings at the bottom you can change rotate, move and scale speed.
#3
If you are looking to just turn an object, something along the lines of:
would work. With the above, I have a gate that moves up when a player enters a trigger. It is a dif object, so using a dts may be easier. Ken Finneys book talks about moving dts's but I don't have that at home. If you just want to turn your object, just set the transform to the new one you want.
01/31/2009 (4:55 am)
Marvin, I would think writing your own entity class using the rotation code from the item class would be the easiest way to accomplish what you are looking to do. You can then set you direction with a 1 or -1 depending on which direction you want to rotate. (or just place your entities in the items class to begin with)If you are looking to just turn an object, something along the lines of:
%trans = nameToId("myEntity").getTransform();
%rot = getWord(%trans, 3)
SPC getWord(%trans, 4)
SPC getWord(%trans, 5)
SPC getWord(%trans, 6);
nameToId("myEntity").setTransform("-145.244 199.162 46.3842" SPC %rot );would work. With the above, I have a gate that moves up when a player enters a trigger. It is a dif object, so using a dts may be easier. Ken Finneys book talks about moving dts's but I don't have that at home. If you just want to turn your object, just set the transform to the new one you want.
#4
That object would then be rotated or scaled or whatever when the player performs some type event.
@Mike Thank you! But one question. will I have to create a new class in the C++ engine or can I do this through TorqueScript?
Where should I put this? Thanks for helping a Newb out?
01/31/2009 (7:49 am)
Thanks Brandon. I'm actually looking for rotating programatically. Basically what I'm thinking I need to do is create a datablock that has all of a DTS file's behaviors in them.That object would then be rotated or scaled or whatever when the player performs some type event.
@Mike Thank you! But one question. will I have to create a new class in the C++ engine or can I do this through TorqueScript?
Where should I put this? Thanks for helping a Newb out?
#5
Like I said, Ken Finneys book talks in depth about this subject.
And you are welcome. I've recieved a ton of help here. :-) Glad I can return some of it.
01/31/2009 (3:31 pm)
You would write a script and place it in server/scripts. If you are only trying to rotate your object in place, like say, turn it 90 degrees in a single direction, it can be done in script. What I was talking about before the script example applies only if you are trying to get your object to rotate like the health kit does.Like I said, Ken Finneys book talks in depth about this subject.
And you are welcome. I've recieved a ton of help here. :-) Glad I can return some of it.
#6
I found the answer in the book: Advanced Game Programming All in One. one problem I'm having though: In Ken's rotate example, I'm trying to rotate: Basically the way this works, the building gets the position of the player: and then turns it toward the player.
It does rotate the object but it only rotates it once. Here's the code? The only thing I changed was the %rotB values: I changed it to 0 0 0 0 just to test it; The rotate still works on the object at the exact same position. So I'm not sure if the position of the player is being determined once and never again. I'm not sure how to update the player's position.
function Findbuilding(%filename)
{
echo("looking for building: "@%filename);// checking to echo stuff
%count = towers.getCount();
%target = 0;
for ( %i = 0; %i < %count; %i++) // an array to find the building and it keeps looking until it finds it
{
%found = towers.getObject(%i);
echo("id:" @ %i @ "-" @ %found.InteriorFile);
if (%found.InteriorFile $= "starter.fps/data/interiors/towers/landtower.dif")
{
%target = %found;
break;
}
}
return %target;
}
function serverCmdRotate1(%client)
{
echo ("*******We be rotatin******");
%avatar = %client.player; //
%bldg = FindBuilding("starter.fps/data/interiors/towers/landtower.dif");
%newTransform = daRotate(%avatar.getTransform(), %bldg);
%bldg.setTransform(%newTransform);
}
function daRotate(%avatar_xform, %obj)
{
%obj_xform = %obj.getTransform();
%rotA = GetWords (%avatar_xform, 3, 6);
%matrixA = " 0 0 0" SPC %rotA;
%rotB = "0 0 0 0"; //360 degrees
echo ("*******rottating object at******" @%rotB);
%matrixB = " 0 0 0" SPC %rotB;
%product = MatrixMultiply (%v1, %v2);
%transform = GetWords(%obj_xform, 0, 2) SPC GetWords(%product, 3, 6);
return %transform;
}
02/03/2009 (8:33 am)
Thanks again Mike.I found the answer in the book: Advanced Game Programming All in One. one problem I'm having though: In Ken's rotate example, I'm trying to rotate: Basically the way this works, the building gets the position of the player: and then turns it toward the player.
It does rotate the object but it only rotates it once. Here's the code? The only thing I changed was the %rotB values: I changed it to 0 0 0 0 just to test it; The rotate still works on the object at the exact same position. So I'm not sure if the position of the player is being determined once and never again. I'm not sure how to update the player's position.
function Findbuilding(%filename)
{
echo("looking for building: "@%filename);// checking to echo stuff
%count = towers.getCount();
%target = 0;
for ( %i = 0; %i < %count; %i++) // an array to find the building and it keeps looking until it finds it
{
%found = towers.getObject(%i);
echo("id:" @ %i @ "-" @ %found.InteriorFile);
if (%found.InteriorFile $= "starter.fps/data/interiors/towers/landtower.dif")
{
%target = %found;
break;
}
}
return %target;
}
function serverCmdRotate1(%client)
{
echo ("*******We be rotatin******");
%avatar = %client.player; //
%bldg = FindBuilding("starter.fps/data/interiors/towers/landtower.dif");
%newTransform = daRotate(%avatar.getTransform(), %bldg);
%bldg.setTransform(%newTransform);
}
function daRotate(%avatar_xform, %obj)
{
%obj_xform = %obj.getTransform();
%rotA = GetWords (%avatar_xform, 3, 6);
%matrixA = " 0 0 0" SPC %rotA;
%rotB = "0 0 0 0"; //360 degrees
echo ("*******rottating object at******" @%rotB);
%matrixB = " 0 0 0" SPC %rotB;
%product = MatrixMultiply (%v1, %v2);
%transform = GetWords(%obj_xform, 0, 2) SPC GetWords(%product, 3, 6);
return %transform;
}
Torque Owner Marvin Hawkins