Rotating objects
by Kirby Frugia · in General Discussion · 11/19/2002 (7:46 pm) · 16 replies
This may seem like a stupid question, but I would like to be able to rotate an object a certain number of degrees/radians along an axis from within a script. For example, I would like to rotate the flagpole in the flagpole.cs script (from the tutorials)? How would I rotate this object from within a script.
Thanks in advance.
Thanks in advance.
#2
This has been done in Quake 3 with the Machine gun's barrel. So maybe good to look at that.
sorry, I can't see really how it does it much anymore, so long since quake 3 lol.
But if you find out how to do this can you tell me please?
11/20/2002 (12:22 am)
To do this, this like is good so you can have the object to stop on each side possible, unlike with an animation, you have it stop only one spot.This has been done in Quake 3 with the Machine gun's barrel. So maybe good to look at that.
sorry, I can't see really how it does it much anymore, so long since quake 3 lol.
But if you find out how to do this can you tell me please?
#3
-Kirby
11/20/2002 (3:32 pm)
Well, I really need to be able to do this and I wouldn't think it would be too difficult. I'm going to try to figure it out. I'll let you know if I discover anything.-Kirby
#4
11/21/2002 (4:24 pm)
You can always change the object's rotation property.
#5
11/26/2002 (5:56 pm)
what do you mean?
#6
11/27/2002 (12:12 pm)
uhh.. nearly every object has a .rotation
#7
11/27/2002 (3:10 pm)
Yes but can you do it from the code? and make it spin?
#8
11/27/2002 (6:29 pm)
You can do .rotation from script. From code its possible too of course, but I bet its mRotation or part of its transform in code, not just the rotation property.
#9
Might be something there ...
11/27/2002 (6:46 pm)
you'de have a script to a setTransform on the object, basically every millisecond to make it look right. For more information, and like, if you want it to rotate smoothly like items, look in the item code (engine code).Might be something there ...
#10
11/27/2002 (10:56 pm)
good idea thanks!
#11
http://www.garagegames.com/index.php?sec=mg&mod=forums&page=result.thread&qt=6770
but it didn't work quite right for me.
Here is the code I used, hope this helps people:
%matrix = %obj.getTransform();
// Get the current transform matrix
%xpos = getWord(%matrix, 0);
%ypos = getWord(%matrix, 1);
%zpos = getWord(%matrix, 2);
// Set the rotation matrix stuff
%xrot = 0;
%yrot = 0;
%zrot = 1;
%angle = ($SomeAngleInDegrees * 3.14) / 180.0;
// apply the transformation.
%obj.setTransform(%xpos @ " " @ %ypos @ " " @ %zpos @ " " @ %xrot @ " " @ %yrot @ " " @ %zrot @ " " @ %angle);
The xrot, yrot, and zrot should be set to 1 or 0 depending on whether the object should rotate on that axis. I was using a StaticShapeData object (the flag in the flagpole tutorial). If you have any questions about this, please let me know and I'll try to explain it (if I can).
12/17/2002 (9:47 pm)
It took me a while, but I figured it out. It may not be the best way to do it, but it worked for me. I got some help from this post (Thanks):http://www.garagegames.com/index.php?sec=mg&mod=forums&page=result.thread&qt=6770
but it didn't work quite right for me.
Here is the code I used, hope this helps people:
%matrix = %obj.getTransform();
// Get the current transform matrix
%xpos = getWord(%matrix, 0);
%ypos = getWord(%matrix, 1);
%zpos = getWord(%matrix, 2);
// Set the rotation matrix stuff
%xrot = 0;
%yrot = 0;
%zrot = 1;
%angle = ($SomeAngleInDegrees * 3.14) / 180.0;
// apply the transformation.
%obj.setTransform(%xpos @ " " @ %ypos @ " " @ %zpos @ " " @ %xrot @ " " @ %yrot @ " " @ %zrot @ " " @ %angle);
The xrot, yrot, and zrot should be set to 1 or 0 depending on whether the object should rotate on that axis. I was using a StaticShapeData object (the flag in the flagpole tutorial). If you have any questions about this, please let me know and I'll try to explain it (if I can).
#12
@ "" @
SPC automatically adds a space between strings, so you can just write
%xrot SPC %yrot ...
12/17/2002 (11:11 pm)
One litte improvement would be to use "SPC" instead of @ "" @
SPC automatically adds a space between strings, so you can just write
%xrot SPC %yrot ...
#13
I have tried to put it in the OnFire function, but don't get any errors etc or any affect, should it be somewhere else?
12/17/2002 (11:29 pm)
How could I ably this to a weapon? so when it fires it spins the weapon? I have tried to put it in the OnFire function, but don't get any errors etc or any affect, should it be somewhere else?
#14
BTW I'm trying to get a weapon to be like the Machine gun from Quake 3 Arena. (basicly)
Thanks!
Edward
12/18/2002 (1:27 am)
Oh I just noticed what it is doing, its turning around the player. How can I make it turn the weapon in stead?BTW I'm trying to get a weapon to be like the Machine gun from Quake 3 Arena. (basicly)
Thanks!
Edward
#15
@Edward:
I haven't had a chance to try it yet, but try replacing every "%obj" with "%this" in the code I sent you (in your onFire method). "%obj" might be referring to the player instead of the weapon. Hopefully this works for you.
Worth a shot. Good luck.
Kirby
12/19/2002 (7:14 am)
@Stefan: Thanks for the suggestion! That is very nice to know.@Edward:
I haven't had a chance to try it yet, but try replacing every "%obj" with "%this" in the code I sent you (in your onFire method). "%obj" might be referring to the player instead of the weapon. Hopefully this works for you.
Worth a shot. Good luck.
Kirby
#16
...
still got this problem. anyone?
12/19/2002 (11:21 pm)
mmm... i get an error saying that it can't find the chaingun transform. any ideas why this is? I'll have to take another look....
still got this problem. anyone?
Torque Owner Dr. John Nobody