Conditional Animation Sequences
by Kirby Webber · in Torque Game Engine · 01/26/2003 (11:43 am) · 22 replies
I have been searching, but not finding exactly what I am looking for.
I have exported 3 animation sequences with a hover vehicle model. (From MS3D... now that was interesting! ;-) ~kudos to the programmers though :D)
What I would like to do is activate each one under specific circumstances.
Animation #1 should be called when the vehicle has rolled/ banked to the left a given number of degrees. Once the final frame of the sequence has been reached, it should hold that frame until the vehicle no longer exceeds the given degree/ angle of roll. At this point, the animation should play backwards until it reaches it's original frame and then stop. (Easy as pie huh?! ;-) )
Animation #2 is the right hand carbon copy of animation #1.
Animation #3 should activate any time the player activates the backward thrust, advancing to the final frame, and holding it until the trigger/ throttle is released, and then play backwards to its original frame and stop.
I know that this can all be done from script (at least think it can be done from script) but am lacking the knowledge, and/or confidence at this point to know where to begin.
If someone could just point me in the right direction, I would be extremely greatful.
Thanks in advance.
P.S.---------------------------------------------------
While I'm at it, I may as well see if I can get some help on these as well:
1) Currently my debris file only activates in player death about 40% of the time... how can I make this 100% of the time?
2) Is there a name specific node that I can add to a model to control the location of the splash emitter?
I have exported 3 animation sequences with a hover vehicle model. (From MS3D... now that was interesting! ;-) ~kudos to the programmers though :D)
What I would like to do is activate each one under specific circumstances.
Animation #1 should be called when the vehicle has rolled/ banked to the left a given number of degrees. Once the final frame of the sequence has been reached, it should hold that frame until the vehicle no longer exceeds the given degree/ angle of roll. At this point, the animation should play backwards until it reaches it's original frame and then stop. (Easy as pie huh?! ;-) )
Animation #2 is the right hand carbon copy of animation #1.
Animation #3 should activate any time the player activates the backward thrust, advancing to the final frame, and holding it until the trigger/ throttle is released, and then play backwards to its original frame and stop.
I know that this can all be done from script (at least think it can be done from script) but am lacking the knowledge, and/or confidence at this point to know where to begin.
If someone could just point me in the right direction, I would be extremely greatful.
Thanks in advance.
P.S.---------------------------------------------------
While I'm at it, I may as well see if I can get some help on these as well:
1) Currently my debris file only activates in player death about 40% of the time... how can I make this 100% of the time?
2) Is there a name specific node that I can add to a model to control the location of the splash emitter?
#2
I do believe that my situation is a little different from yours, but the advice, and the example are still quite valid.
Your help is greatly apprecitated. ;-)
01/29/2003 (6:34 am)
This is definitely a step in the right direction. Thank you for your invaluable help Matthew. I think this will be exactly what I needed to get going on this!I do believe that my situation is a little different from yours, but the advice, and the example are still quite valid.
Your help is greatly apprecitated. ;-)
#4
I have been playing around with your suggestions. Most noteably, calling playThread() from the movement function on the backwards animation.
What is strange is that it doesn't seem to work. I have tested the animation from the control script (i.e. %obj.playThread(#, "Name");) and everything works fine.
The problem seems to be the $player reference not connecting to the actual vehicle itself?!
Incidentally, I am currently not concerned about the timing, or pausing the animation. I will get to that, but for now just want to get it activated in-game. ;-) Baby-steps. :D
I have tried every variation of the command that I can think of, but still it doesn't work?!
Any thoughts or additional advice?
01/29/2003 (10:20 am)
Okay then, I will... ;-)I have been playing around with your suggestions. Most noteably, calling playThread() from the movement function on the backwards animation.
What is strange is that it doesn't seem to work. I have tested the animation from the control script (i.e. %obj.playThread(#, "Name");) and everything works fine.
The problem seems to be the $player reference not connecting to the actual vehicle itself?!
Incidentally, I am currently not concerned about the timing, or pausing the animation. I will get to that, but for now just want to get it activated in-game. ;-) Baby-steps. :D
I have tried every variation of the command that I can think of, but still it doesn't work?!
Any thoughts or additional advice?
#5
Now if you do that then what I wrote will work.
You also can go into the console via tilde key while in game and type $player.dump(); and get a complete list of all the functions that apply to that instance of that player. Which is really a wheeled vehicle.
Of course I don't think that keeping it that way ($player) is going to work in a game. I think it might cause a conflict between server and client when more then one client is on the server(I really am not sure) but to be safe we have evolved it a little to avoid any conflict. But once you start figuring it out, you'll be able to set that up yourself.
We have started writing a new class for vehicles that allows Threads to be played according to movement and action. Similiar to the way the player class works but with vehicle physics. I can't tell you how long its going to take to get 100% but when its done I am going to give the resource out. So if you can't get what you want from the script then that might be somthing you think about doing to the code.
Hope that helps, let me know.
Matt
01/29/2003 (10:41 am)
Oh the $player is unique to the way I wrote my script. Now I am not sure what set of files your using but when I did mine I used the racing MOD. In example/racing/server/scripts/GAME.CS I changed the create player function from:function GameConnection::createPlayer(%this, %spawnPoint)
{
if (%this.player > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}
%player = new WheeledVehicle() {
dataBlock = DefaultCar;
client = %this;
};
MissionCleanup.add(%player);
// Car setup...
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);
// Update the camera to start with the car
%this.camera.setTransform(%player.getEyeTransform());
// Give the client control of the car
%this.player = %player;
%this.setControlObject(%player);
}The above is origanal and is probably the way you will find it. Notice the line that says:%player = new WheeledVehicle()The percent sign(%) makes the variable local and as far as I was able to get you can't call on %player outside this script. I changed this and every instance of %player in the game.cs to "$player". The doller sign makes it global. Global can be accessed from any script.
Now if you do that then what I wrote will work.
You also can go into the console via tilde key while in game and type $player.dump(); and get a complete list of all the functions that apply to that instance of that player. Which is really a wheeled vehicle.
Of course I don't think that keeping it that way ($player) is going to work in a game. I think it might cause a conflict between server and client when more then one client is on the server(I really am not sure) but to be safe we have evolved it a little to avoid any conflict. But once you start figuring it out, you'll be able to set that up yourself.
We have started writing a new class for vehicles that allows Threads to be played according to movement and action. Similiar to the way the player class works but with vehicle physics. I can't tell you how long its going to take to get 100% but when its done I am going to give the resource out. So if you can't get what you want from the script then that might be somthing you think about doing to the code.
Hope that helps, let me know.
Matt
#6
Forgive my enthusiasm, but you just blew the lid off this thing for me!
Thanks for your help... and your patience! :D
01/29/2003 (10:55 am)
YOU DA MAN!!!!! :DForgive my enthusiasm, but you just blew the lid off this thing for me!
Thanks for your help... and your patience! :D
#7
Is it possible to handle multiple threads in this fashion?
Let me explain: The vehicle I have created is designed to have 2 airfoils (airbrakes), one on each side.
What I am experimenting with is this: when the player activates the left strafe, the left foil animation is activated, and then the function is mirrored for the right foil.
What is strange are the in-game results: both foils will animate once, and then only the last one used will work. i.e. if you press the left strafe, the left foil animates. Press the right strafe and the right foil animates. Press the left strafe again and nothing happens.
Any ideas? Something I am missing here?
Here's the code to be on the 'safe' side:
P.S.
I plan to run an experiment if I get this working correctly across my network. Since remote connections *should* be labeled as clients by the engine, I am doubtful as to whether or not globaly defining $player will have any effect. I'll let you know if I find anything. ;-)
01/29/2003 (2:29 pm)
Matt,Is it possible to handle multiple threads in this fashion?
Let me explain: The vehicle I have created is designed to have 2 airfoils (airbrakes), one on each side.
What I am experimenting with is this: when the player activates the left strafe, the left foil animation is activated, and then the function is mirrored for the right foil.
What is strange are the in-game results: both foils will animate once, and then only the last one used will work. i.e. if you press the left strafe, the left foil animates. Press the right strafe and the right foil animates. Press the left strafe again and nothing happens.
Any ideas? Something I am missing here?
Here's the code to be on the 'safe' side:
//********************************************
function moveleft(%val) //*
{ //*
$mvLeftAction = %val; //*
if (%val) { //*
$player.playThread(1, "LFoil"); //*
schedule(500,0,"pauseLAnim",1); //*
} //*
//*
if (!%val) { //*
$player.playThread(1, "LFoil"); //*
$player.stopThread(1); //*
} //*
} //*
//*
//*
function pauseLAnim() //*
{ //*
$player.pauseThread(1); //*
} //*
//*
function moveright(%val) //*
{ //*
$mvRightAction = %val; //*
if (%val) { //*
$player.playThread(2, "RFoil"); //*
schedule(500,0,"pauseRAnim",2); //*
} //*
//*
if (!%val) { //*
$player.playThread(2, "RFoil"); //*
$player.stopThread(2); //*
} //*
} //*
//*
//*
function pauseRAnim() //*
{ //*
$player.pauseThread(2); //*
} //*
//********************************************P.S.
I plan to run an experiment if I get this working correctly across my network. Since remote connections *should* be labeled as clients by the engine, I am doubtful as to whether or not globaly defining $player will have any effect. I'll let you know if I find anything. ;-)
#8
Of course that abbreviated. I don't like the new CODE bars you can't copy/paste from them. That should tell it when the %val stops go ahead and finish and then stop the animation. As long as your animation starts and stops in the right place you shouldn't have any problems.
Also make sure when you export your MODEL using MAX2DTS that your DTS helper object has certian properties checked off on it.
complete cycle== this tells the animation to play one time and then stop.
Blending sequence == able to play while others are playing.
If your animations are Cyclic that means they play and stay in a play mode for the entire time the model is loaded. They also don't blend well. Thats been my experience. if you mark the other 2 boxes you should be OK. You can start and stop the Thread from playing anytime and play it while other play.
Also make sure when using your playThread you set your animation number:
The animations need to be numbered between 0-3. Four total. The engine will disregard anything 4+. At least in the wheeled Vehicle it does.
I wasn't really worried about the server client problem. As far as our game design goes we made sure That it wouldn't by implementing a different value for everyplayer depending on 2 things. In the gui you can decide what person you are and what vehicle you want. By deciding those 2 things you generate a value that is unique to you. We use it for other things as well. One guy might or might not handle the vehicle better than the next but he can get more speed ect. ect... Then you have a profile also that comes into play. So by doing it that way we eliminated the chance of 2 clients being the same name. Its kinda deep my programmer set it up.
Hope that helps again.
Oh ya just play with the model and the script you'll get it tuned just right. I spent close to 2 weeks getting my firat vehicle tuned and most of them after have taken at least a couple of days.
Matt
01/29/2003 (4:35 pm)
Instead of using 2 IF statements just do like this:If (val) Playthread (1) schedule (pause) else playthread (1) stopthread(1) ect.....
Of course that abbreviated. I don't like the new CODE bars you can't copy/paste from them. That should tell it when the %val stops go ahead and finish and then stop the animation. As long as your animation starts and stops in the right place you shouldn't have any problems.
Also make sure when you export your MODEL using MAX2DTS that your DTS helper object has certian properties checked off on it.
complete cycle== this tells the animation to play one time and then stop.
Blending sequence == able to play while others are playing.
If your animations are Cyclic that means they play and stay in a play mode for the entire time the model is loaded. They also don't blend well. Thats been my experience. if you mark the other 2 boxes you should be OK. You can start and stop the Thread from playing anytime and play it while other play.
Also make sure when using your playThread you set your animation number:
player.playThread(1,run); The one is your animation number, Thats what you will use for pause and stop.
The animations need to be numbered between 0-3. Four total. The engine will disregard anything 4+. At least in the wheeled Vehicle it does.
I wasn't really worried about the server client problem. As far as our game design goes we made sure That it wouldn't by implementing a different value for everyplayer depending on 2 things. In the gui you can decide what person you are and what vehicle you want. By deciding those 2 things you generate a value that is unique to you. We use it for other things as well. One guy might or might not handle the vehicle better than the next but he can get more speed ect. ect... Then you have a profile also that comes into play. So by doing it that way we eliminated the chance of 2 clients being the same name. Its kinda deep my programmer set it up.
Hope that helps again.
Oh ya just play with the model and the script you'll get it tuned just right. I spent close to 2 weeks getting my firat vehicle tuned and most of them after have taken at least a couple of days.
Matt
#9
Here is an example screen shot, I copied the code directly and pasted it into Notepad with no editing.
Code Fragement Rendered in Mozilla
01/29/2003 (5:46 pm)
Using Mozilla I can copy/paste code blocks just fine. I think they look awesome!Here is an example screen shot, I copied the code directly and pasted it into Notepad with no editing.
Code Fragement Rendered in Mozilla
#10
Yep your right Mozilla is the ticket I'll use it when I come to GG site.
01/29/2003 (6:47 pm)
I wouldn't doubt Mozilla does a better job than IE. Most other browsers do. Yep your right Mozilla is the ticket I'll use it when I come to GG site.
#11
As for the animations, I am at work right now, so it'll be a while before I can try this out. =/
I do have question though. I am using MilkShape to export my vehicle model. I know from the exporter docs, that I can export cyclic or non-cyclic animations, but I am not sure what you mean by "complete-cycle"? Is there an equivalent for MS3D, or do you mean to simply use non-cyclic animations?
Again, I really appreciate your help and patience. =)
P.S.
After some experimenting, I realized that I CAN copy and paste the code blocks in IE 6+. Granted, in Notepad the formatting gets trashed, but in WordPad, everything is perfect!
01/30/2003 (6:29 am)
Wow, that's sweet Jarrod... I may have to consider switching from IE! ;-)As for the animations, I am at work right now, so it'll be a while before I can try this out. =/
I do have question though. I am using MilkShape to export my vehicle model. I know from the exporter docs, that I can export cyclic or non-cyclic animations, but I am not sure what you mean by "complete-cycle"? Is there an equivalent for MS3D, or do you mean to simply use non-cyclic animations?
Again, I really appreciate your help and patience. =)
P.S.
After some experimenting, I realized that I CAN copy and paste the code blocks in IE 6+. Granted, in Notepad the formatting gets trashed, but in WordPad, everything is perfect!
#12
Matt
01/30/2003 (11:11 am)
Oh well my instructions were for 3dsMAX so it might be different in Milkshape I don't know if you got as many options in there or not. I never even used the MS exporter.Matt
#13
01/30/2003 (11:20 am)
I'll try it out with plain ole' non-cyclic animations and see what happens. The more I think about it, the more that stands to reason. ;-)
#14
@Matthew: I am using IE 5.5 (can't speak for 6) and if I copy and paste a part of the code in a code bar, Notepad doesn't recognize the CRs, and Wordpad ignores the indentation. If I paste to Word, I get both (but it is butt ugly) - then I copy that and paste to Notepad and all is well.
However, if I copy the entire code bar contents, it pastes into Wordpad as purty as you please.
Thought that might help.
Tim
[edit: Wordpad in last sentence (not Notepad)]
01/30/2003 (2:36 pm)
Really going off in the wrong direction but...@Matthew: I am using IE 5.5 (can't speak for 6) and if I copy and paste a part of the code in a code bar, Notepad doesn't recognize the CRs, and Wordpad ignores the indentation. If I paste to Word, I get both (but it is butt ugly) - then I copy that and paste to Notepad and all is well.
However, if I copy the entire code bar contents, it pastes into Wordpad as purty as you please.
Thought that might help.
Tim
[edit: Wordpad in last sentence (not Notepad)]
#15
Matt
01/30/2003 (5:33 pm)
Ya that works for 6 also. I somtimes open 2 windows when I am responding to a post and copy paste back and forth so I don't have to type so much. IE won't let me do it nicely but the mozilla does. Also fixes webpages up when using large font. I like that to. I don't really care just so I can get around.Matt
#16
Here's where I'm at:
I did a clean export and tagged all of the animations non-cyclic...
I had to set a stop function for each animation, and set a shcedule to call it. The way it was written, it cut the thread short and just stopped.
That would all be well and good, but the problem of one thread 'overriding' the other persists. Activate one animation, fine. Activate the other animation, fine. Activate the original animation, nothing!
I have poured over the MilkShape documentation (ms2dts) and can find nothing that addresses this specifically. I am really starting to wonder about the blending and other options you mentioned previously...
Just in case:
Any other thoughts?
01/30/2003 (6:00 pm)
Hmmm.... Here's where I'm at:
I did a clean export and tagged all of the animations non-cyclic...
I had to set a stop function for each animation, and set a shcedule to call it. The way it was written, it cut the thread short and just stopped.
That would all be well and good, but the problem of one thread 'overriding' the other persists. Activate one animation, fine. Activate the other animation, fine. Activate the original animation, nothing!
I have poured over the MilkShape documentation (ms2dts) and can find nothing that addresses this specifically. I am really starting to wonder about the blending and other options you mentioned previously...
Just in case:
//********************************************
function moveleft(%val) //*
{ //*
$mvLeftAction = %val; //*
if (%val) { //*
$player.playThread(0, "LFoil"); //*
schedule(500,0,"pauseLAnim",0); //*
} //*
//*
else { //*
$player.playThread(0, "LFoil"); //*
schedule(500,0,"stopLAnim",0); //*
} //*
} //*
//*
function stopLAnim(%val) //*
{ //*
$player.stopThread(0); //*
} //*
//*
function pauseLAnim(%val) //*
{ //*
$player.pauseThread(0); //*
} //*
//*
function moveright(%val) //*
{ //*
$mvRightAction = %val; //*
if (%val) { //*
$player.playThread(1, "RFoil"); //*
schedule(500,0,"pauseRAnim",1); //*
} //*
//*
else { //*
$player.playThread(1, "RFoil"); //*
schedule(500,0,"stopRAnim",1); //*
} //*
} //*
//*
function stopRAnim(%val) //*
{ //*
$player.stopThread(1); //*
} //*
//*
function pauseRAnim(%val) //*
{ //*
$player.pauseThread(1); //*
} //*
//********************************************Any other thoughts?
#17
I like to proccess the pauses and extras before I actually run the function that uses them. I don't think that makes a difference. But the stop doesn't need to be on a schedule. Essentially the way I got it the animation will play the rest of the way and STOP due to it is not cyclic. Then you use the stop thread to Kinda reset and totally stop any part of that thread. The schedule might not sync up (FOR some reason???) an you are not finished with the Thread so it won't play another.
Blending sequence is pretty important. I couldn't get anything to work until I used it.
If you continue to have a problem you can send me the model and the skin (3ds) and a decription of how its animated and I will reexport and retag it for you through MAX. mjones7947@comcast.net. Other than that I don't know what to tell ya if Milkshape doesn't have blending in its exporter.
Good luck let me know.
Matt
01/31/2003 (4:40 am)
Try to rearrange your script a little and get rid of the stop animation.function pauseLAnim(%val) //*
{ //*
$player.pauseThread(0); //*
} //*
function moveleft(%val) //*
{ //*
$mvLeftAction = %val; //*
if (%val) { //*
$player.playThread(0, "LFoil"); //*
schedule(500,0,"pauseLAnim",0); //*
} //*
//*
else { //*
$player.playThread(0, "LFoil"); //*
$player.stopThread(0); //*
} //*
} //*
//*I like to proccess the pauses and extras before I actually run the function that uses them. I don't think that makes a difference. But the stop doesn't need to be on a schedule. Essentially the way I got it the animation will play the rest of the way and STOP due to it is not cyclic. Then you use the stop thread to Kinda reset and totally stop any part of that thread. The schedule might not sync up (FOR some reason???) an you are not finished with the Thread so it won't play another.
Blending sequence is pretty important. I couldn't get anything to work until I used it.
If you continue to have a problem you can send me the model and the skin (3ds) and a decription of how its animated and I will reexport and retag it for you through MAX. mjones7947@comcast.net. Other than that I don't know what to tell ya if Milkshape doesn't have blending in its exporter.
Good luck let me know.
Matt
#18
I completely abandoned the moveright and moveleft animations, and then tried to reinstate the back animation... guess what...
My default.bind.cs script is not recompiling?!?!
Parsing through what I can understand of the *.cs.dso file, it is still refering to a command set that is 3 revisions old!
Why might this be? Any thoughts, or better yet, work arounds?
[edit]
NM... I think I got it.
01/31/2003 (9:58 pm)
I ran an experiment on a hunch.I completely abandoned the moveright and moveleft animations, and then tried to reinstate the back animation... guess what...
My default.bind.cs script is not recompiling?!?!
Parsing through what I can understand of the *.cs.dso file, it is still refering to a command set that is 3 revisions old!
Why might this be? Any thoughts, or better yet, work arounds?
[edit]
NM... I think I got it.
#19
Matt
02/01/2003 (5:07 am)
Just start your engine.Before you start your game access the console via the TILDE key. If you have errors in the .CS file it will debug and and tell you about where the error is. If you don't get any errors there then load a game and then go to the console. Probably just forgot some simple syntax. I usually forget to put the ";" at the end of a line inside a function. If you deleted somthing you probably left somthing from the old code and it doesn't know how to make sense of it.Matt
#20
In the meantime... I'll probably feel really stupid when I hear the answer, but I've been searching for this mysterious Showtool that their seems to be no information on, and that seems to be oddly absent from my SDK.
If this tool is what I think it is, then it will gretaly reduce my animation testing time! Where, how do I get this thing? Any thoughts?
Also: Tried restructuring my skeleton as I had previously created 2 unappended nodes from which the animations played. It was my hope that possibly two nodes vaiing(sp?) for control might have caused Animatus Interruptus.
This time I set them up from a parental hiearchy, but the results were the same. I'll ge this yet! =/
02/01/2003 (7:29 pm)
Y'know Matthew, I meant to thank you for your generous offer to export the animated mesh for me, but with the volume of art I'll be cranking out, I really need to find a way to make this all work. ;-)In the meantime... I'll probably feel really stupid when I hear the answer, but I've been searching for this mysterious Showtool that their seems to be no information on, and that seems to be oddly absent from my SDK.
If this tool is what I think it is, then it will gretaly reduce my animation testing time! Where, how do I get this thing? Any thoughts?
Also: Tried restructuring my skeleton as I had previously created 2 unappended nodes from which the animations played. It was my hope that possibly two nodes vaiing(sp?) for control might have caused Animatus Interruptus.
This time I set them up from a parental hiearchy, but the results were the same. I'll ge this yet! =/
Torque Owner Matthew Jones
The backwards you can do by using playThread. When using play Thread you only get 4 animations. All the others are not loaded.You'll need to make sure you know the exact timeframe of your animations. Say for example its 1 second long, The script (default.bind) would go as follows.
//// You need a pause function first to stop the animation half way between while the your moving backwards. function pausebackanim(%val) { $player.pauseThread(3); { function movebackward(%val) { $mvBackwardAction = %val; if (%val) { $player.playthread(3,backward); schedule(500,0,"pauseBackAnim",1); } //// The we need to tell it if the value of move backwards has stopped to go on ahead and play the rest of the animation then stop if (!%val) { $player.playthread(3,backward); $player.stopthread(3); } }Hopefully you understand what I am saying. I assuming your animation leans to the back then leans towards the front and is finished. So basically we told it play half the animation the stop moving until the backward command is stopped then finish the thread by leaning back forward and going into normal mode. You'can't quate me on my script there is probably somthing wrong with it but hopefully it will help you get the idea.
The splash point Idon't believe is a designated node in the model. You could put one in buit you might have to add somthing to engine to make it work.
Hope I helped you some
Matt