Help controlling a tractor
by Douglas Higa · in General Discussion · 04/06/2006 (9:57 am) · 10 replies
I want to control a tractor by keyboard in Torque. My problem is that it has many "points" (nodes, joints, i dont know the correct name) to animate and they rotate to all directions. The texts I have found up to now are about cars that only move their wheels to right and left. Im just a begginer with Torque, if anyone could give me an idea I will be very grateful.
#2
Thanks for your help. Now, Im trying to use animations made with Milkshape, but i still have a few questions:
- My tractor has an arm that have an animation up/down. In the end of the arm there is a "hand" that shoud have another animation, but the position of this "hand" is not static because the arm can move up/down. Is it possible to animate the "hand"?
- Do I need to separate my tractor in many parts and mount it in Torque?
- Do I need to use .dqs files? And why?
- I saw a post in this forum that used the command playThread and pauseThread, but it didnt work with me. Am I in the right way or i need to use another code?
04/10/2006 (10:26 am)
Badguy,Thanks for your help. Now, Im trying to use animations made with Milkshape, but i still have a few questions:
- My tractor has an arm that have an animation up/down. In the end of the arm there is a "hand" that shoud have another animation, but the position of this "hand" is not static because the arm can move up/down. Is it possible to animate the "hand"?
- Do I need to separate my tractor in many parts and mount it in Torque?
- Do I need to use .dqs files? And why?
- I saw a post in this forum that used the command playThread and pauseThread, but it didnt work with me. Am I in the right way or i need to use another code?
#3
1.) I'm not 100% sure if this method supports blended animations I dont see why not maybe someone who really knows can answer this one.
2.) you should not have to but it is an option (split tractor)
3.) you mean dsq files?, they are simply animation files you can burn them into the dts or have seperated dsq this should not make a difference.
4.) playThread and pauseThread should work. you need to script which animations are loaded you can locate a simple item script to anaylze (perhaps even a character script)
04/10/2006 (10:35 am)
Douglas:1.) I'm not 100% sure if this method supports blended animations I dont see why not maybe someone who really knows can answer this one.
2.) you should not have to but it is an option (split tractor)
3.) you mean dsq files?, they are simply animation files you can burn them into the dts or have seperated dsq this should not make a difference.
4.) playThread and pauseThread should work. you need to script which animations are loaded you can locate a simple item script to anaylze (perhaps even a character script)
#4
04/10/2006 (11:31 am)
Thanks again. I'll see what i can do here
#5
Can I play and pause the animation timeline when I want? Example: there is an arm animation with the rotation 0
04/11/2006 (9:57 am)
Badguy, could you please give us an example about coding an animation? I know to export a DTS shape with an animation on it (root, run, etc) but I want to specify a different name (some that Torque engine don't have) and play this animation via script with the press of a button keyboard. How do I do this??Can I play and pause the animation timeline when I want? Example: there is an arm animation with the rotation 0
#6
State machine?
Pasue and play...dont think so.
04/11/2006 (10:16 am)
Key binds to trigger animations?State machine?
Pasue and play...dont think so.
#7
I wont try to mislead you its been a long time since I've played with the torque.
lets start with the keypress, if you search the script code for the waving animation
(press w i think?)
there is some code to setup a keypress animation.
in order to have a "Different" animation, view the script file that resides beside the dts file for the player.
this file is used to specify available animations for the given model, if you have a unique one ready you can add it here and reference it with your new "Wave" script code.
as for pausing and playing Im not 100% sure, but Im thinking you can use pauseThread to help facilitate a blocking animation.
04/11/2006 (11:44 am)
FAROF:I wont try to mislead you its been a long time since I've played with the torque.
lets start with the keypress, if you search the script code for the waving animation
(press w i think?)
there is some code to setup a keypress animation.
in order to have a "Different" animation, view the script file that resides beside the dts file for the player.
this file is used to specify available animations for the given model, if you have a unique one ready you can add it here and reference it with your new "Wave" script code.
as for pausing and playing Im not 100% sure, but Im thinking you can use pauseThread to help facilitate a blocking animation.
#8
04/12/2006 (4:50 am)
Hi, I need to do something like that too, but I have no idea how to do it. I beg you guys, please could anyone give me an script example?
#9
04/12/2006 (4:56 am)
Hi, I need to do something like that too, but I have no idea how to do it. I beg you guys, please could anyone give me an script example?
#10
After a long week I finally think I'm having some progress here. Now, I can control my tractor using playThread and pauseThread (there are others functions), but there is a problem: I only do this by the console. I did like this:
1) make a shape in MilkShape and animate it. The shape I named as "tractor" and the animation as "test". After this I exported it to .dts and saved in data/shapes/tractor.
2) create a tractor.cs file in server/scripts, where I wrote this:
datablock ItemData(Tractor){
category="Tractor";
className="Test";
shapeFile="~/data/shapes/tractor/tractor.dts";
mass=1;
eyeoffset="0 -330 -211";
friction=1;
};
function InsertTractor(){
$Tractor=new Item(){
rotation="0 0 1 0";
scale="1 1 1";
dataBlock= "Tractor";
};
MissionCleanup.add($Tractor);
$Tractor.setTransform( "-45.8946 -21.6984 211.921");
}
function ServerCmdStartMoveAnim(){
$Tractor.playThread(0,"test");
echo("play"); //just to see in console if it worked
}
function ServerCmdStopPlayerMoveAnim(){
$Tractor.pauseThread(0);
echo("pause");
}
3) In server/scripts/game.cs, add this line:
exec("./tractor.cs");
and this too:
function onMissionLoaded()
{
// Called by loadMission() once the mission is finished loading.
// Nothing special for now, just start up the game play.
startGame();
insertTractor(); //LINE ADDED
}
4) In client/scripts/default.bind.cs, I add:
moveMap.Bind(Keyboard, m, StartPlayerMoveAnim );
moveMap.Bind(Keyboard, j, StopPlayerMoveAnim );
function StartPlayerMoveAnim(){
commandToServer('StartPlayerMoveAnim'); //THIS FUNCTION IS IN TRACTOR.CS
}
function StopPlayerMoveAnim(){
commandToServer('StopPlayerMoveAnim');
}
5) Delete all .dso files and client/config.cs and client/prefs.cs
So, what it should have happened: the tractor shoud be created automatically in the event OnMissionLoaded, and then I would be able to use the variable $Tractor to control it by the functions playThread and pauseThread, but it didnt happened.
So, I placed the tractor myself using the world creator and saved my world. And then, using the ID of the tractor I could control it typing this in the console (and it worked!):
[id].playthread(0,"test");
Well, the code was adapted from an example of Michael Hense (thank you!). Please, anyone knows what i did wrong?
04/13/2006 (7:31 am)
Pedro,After a long week I finally think I'm having some progress here. Now, I can control my tractor using playThread and pauseThread (there are others functions), but there is a problem: I only do this by the console. I did like this:
1) make a shape in MilkShape and animate it. The shape I named as "tractor" and the animation as "test". After this I exported it to .dts and saved in data/shapes/tractor.
2) create a tractor.cs file in server/scripts, where I wrote this:
datablock ItemData(Tractor){
category="Tractor";
className="Test";
shapeFile="~/data/shapes/tractor/tractor.dts";
mass=1;
eyeoffset="0 -330 -211";
friction=1;
};
function InsertTractor(){
$Tractor=new Item(){
rotation="0 0 1 0";
scale="1 1 1";
dataBlock= "Tractor";
};
MissionCleanup.add($Tractor);
$Tractor.setTransform( "-45.8946 -21.6984 211.921");
}
function ServerCmdStartMoveAnim(){
$Tractor.playThread(0,"test");
echo("play"); //just to see in console if it worked
}
function ServerCmdStopPlayerMoveAnim(){
$Tractor.pauseThread(0);
echo("pause");
}
3) In server/scripts/game.cs, add this line:
exec("./tractor.cs");
and this too:
function onMissionLoaded()
{
// Called by loadMission() once the mission is finished loading.
// Nothing special for now, just start up the game play.
startGame();
insertTractor(); //LINE ADDED
}
4) In client/scripts/default.bind.cs, I add:
moveMap.Bind(Keyboard, m, StartPlayerMoveAnim );
moveMap.Bind(Keyboard, j, StopPlayerMoveAnim );
function StartPlayerMoveAnim(){
commandToServer('StartPlayerMoveAnim'); //THIS FUNCTION IS IN TRACTOR.CS
}
function StopPlayerMoveAnim(){
commandToServer('StopPlayerMoveAnim');
}
5) Delete all .dso files and client/config.cs and client/prefs.cs
So, what it should have happened: the tractor shoud be created automatically in the event OnMissionLoaded, and then I would be able to use the variable $Tractor to control it by the functions playThread and pauseThread, but it didnt happened.
So, I placed the tractor myself using the world creator and saved my world. And then, using the ID of the tractor I could control it typing this in the console (and it worked!):
[id].playthread(0,"test");
Well, the code was adapted from an example of Michael Hense (thank you!). Please, anyone knows what i did wrong?
Torque Owner Badguy
ie:
Raise bucket, Lower bucket, extend bucket.
all of these would need to be coded from scratch.
not really a big deal.
depending on how you handle it.
if you use animations it could probably be pretty easy.
if you use joints and perform the rotations yourself, it might get more complex but still very doable.