How to call animation in crossbow.cs?
by none · in Torque Game Engine · 01/30/2010 (9:04 pm) · 16 replies
*Edit- Ok basically all I need to know now is how to make my first person weapon play an animation. The animation I have made is called "ready.dsq" and I want it to play during the ready state. It's a cyclic animation and it is from frames 1-10. Where do I define to play the animation?
#2
01/30/2010 (10:14 pm)
I'll try that. But also, in my M16.cs file, where do I call an animation and what lines of code would I use. For example. My fps model has an animation called "idle.dsq" I want this to play during the "Ready" state. The animation is 10 frames long and is cyclic. How do I make this animation play during this state?
#3
02/01/2010 (1:40 pm)
try including the sequence in the state management code. There should be a "stateSequence[i] = "yourAnimationSeq"; (NOT "yourAnimationSeq.dsq")" for any given state and (with Milkshape)the sequence should be exported with the DTS as a sequence, NOT a separate DSQ. I don't know if your using Milkshape or TGE but after reading your post, it sounds like you may be exporting the animation as a separate DSQ which (from my experiences) does not work for shapeImages. Hope this helps!!!
#4
02/01/2010 (5:28 pm)
:) Yea, I've been using DSQ's! That would explain alot! Thanks very much haha! One question, how to I make them just be embedded with the DTS? And does this mean I could make my own sequences aside from "Activate, Fire, Reload, and Deactivate"? For instance if I wanted to have a sequence for Ready, where the gun just bobs up and down to simulate breathing, how would I do this?
#5
02/01/2010 (5:44 pm)
Just create your weapon animation as usual, export it as part of the DTS file (don't know how to do this in Milkshape), and add it to the 'ready' state as RealmX said. Note that the gun will stop bobbing when you fire, or reload, or change state at all.
#6
02/01/2010 (5:48 pm)
Ok, I'll try this, thanks. I'll let you know how it goes!
#7
02/01/2010 (9:56 pm)
Ok, this is really, really bugging me. The animations are all embedded into the dts file. Yet none of the animations work when they are supposed to. They are named as followed, "Activate, Ready, Fire, Reload, NoAmmo" They are all called under statesequences.
#8
Try using the crossbow script for your weapon - since we know that should work. If the crossbow script doesn't work, then it's a problem with your art, and I can't help you :P.
EDIT: Oh, if it is an art problem, try checking the sequences in TSTPro.
02/02/2010 (5:06 am)
Console errors?Try using the crossbow script for your weapon - since we know that should work. If the crossbow script doesn't work, then it's a problem with your art, and I can't help you :P.
EDIT: Oh, if it is an art problem, try checking the sequences in TSTPro.
#9
02/02/2010 (10:39 am)
I am using the crossbow script. I have made no changes to it at all. Ok sounds good, I'll check out the model in TSTPro. By the way, thanks guys for being helpful, I'm quite the newb when it comes to anything that has the least bit of scripting. :D
#10
stateName[i] = "PlayAnim";
stateScript[i] = "playAnim";
stateTransitionOnTimeOut[i] = "Fire";
stateTimeout[i] = "should match your character animation";
// after the state machine code somewhere under onFire...
function playAnim()
{
Player.stopThread(slotNum);
Player.playThread(slotNum, "threadName");
}
I think the stateSequences only apply to the actual weapon (MyWeaponImage).
After you said you're trying to simulate breathing, I figured you're probably trying to call character animations. Try including the breathing motion of the character in its animations. That way, you don't have to call it from the state machine. If you check Kork (Ork...whatever his name is) in TSTPro you'll notice he is breathing in his root animation if I'm not mistaken. Again, I hope this helps!!!
02/02/2010 (11:47 am)
When you say "not working when they're supposed to" do you mean they're working, but at the wrong time, or they're not working at all? It may be a timing issue solved by adjusting the stateTimeOut value or the animations themselves. Are the animations blended? Are you trying to call a character animation with these sequences? If you are, it ain't gonna work. I've only been able to call a character animation via stateSequence through script:stateName[i] = "PlayAnim";
stateScript[i] = "playAnim";
stateTransitionOnTimeOut[i] = "Fire";
stateTimeout[i] = "should match your character animation";
// after the state machine code somewhere under onFire...
function playAnim()
{
Player.stopThread(slotNum);
Player.playThread(slotNum, "threadName");
}
I think the stateSequences only apply to the actual weapon (MyWeaponImage).
After you said you're trying to simulate breathing, I figured you're probably trying to call character animations. Try including the breathing motion of the character in its animations. That way, you don't have to call it from the state machine. If you check Kork (Ork...whatever his name is) in TSTPro you'll notice he is breathing in his root animation if I'm not mistaken. Again, I hope this helps!!!
#11
02/02/2010 (5:31 pm)
Quote:function playAnim()Arg, I'd forgotten about this. Depending on how it works, this may be a solution to the weapon-bobs-when-moving goal.
{
Player.stopThread(slotNum);
Player.playThread(slotNum, "threadName");
}
#12
02/02/2010 (10:44 pm)
Got it working! For some reason the animations worked fine in Milkshape but got corrupted in the export! Thank you very much guys! So that I don't have to make a new post, does anyone know what settings to put on to make a mesh only appear during one frame? Thanks!
#13
Alternatively, consider using Explosions for muzzle flashes, though that might take code changes.
02/02/2010 (11:59 pm)
Ah, the muzzle flash conundrum? :P I think Torque has something called 'visibility animations' - at least the Blender exporter does. I've never really done much with them, but it seems like they should allow you to control the mesh's visibility.Alternatively, consider using Explosions for muzzle flashes, though that might take code changes.
#14
02/03/2010 (12:07 am)
I've read up on the visibility thing. I see the options in milkshape and have experimented with them a bit, I just can't find anything really guiding me as to how to make it work. I don't wanna do a particle system, because I'm making an M16A1 and I definitely want it to have that classic (and overly exaggerated) muzzle flash. I have already created the model for this, I'm just having issues making it only appear on a certain frame. Thanks for all the help again! :)
#15
I think by default, all meshes should render[IE, visible] in all Frames of the Timeline; until you begin to attach an 'alpha' level to the meshes.
For example; say you have the Milkshape3D Timeline with 10 frames of animation, with all sequences separated and defined. Now, say your 'fire' sequence is 3 frames in length[doesn't matter where in the Timeline, just that the sequence and frames are defined], and falls on the last 3 frames[8,9,&10].
Now say you want your lovely muzzleFlash geometry[with alpha mask as well!] to only be visible for one single frame, say frame#2 of the 'Fire' sequence. This frame#2[actually Frame#9 of Timeline] will need to have a 'Visibility' matters array flag set. This is done by using the ADD button, then the Edit button[another popper appears], with a Frame and Alpha entry boxes. So, for this example, I would ADD 3 Visibility flags; entering "0" for Frame#8 and Frame#9, while entering "1"(or whatever transparency level you wish] for Frame#9. I would also create the Visibility flags in order of need, with Frame8 listed first, Frame9 next, and Frame10 last. Finish off with OK to close the Edit box, and you now 'should' have a Visibility Animation ready for export.
Since you only want this geometry to appear during 'Fire' and no other sequences in Timeline, you need to place the "0" Alpha value in the first frame of "Fire"; this 'should' keep that geometry 'invisible' until Frame9 of the Timeline, and then needs to be turned 'OFF' in Frame10.
Hope this helps.
PS: don't forget to set your Material transparency flag as well, if ya got/using one!
If someone with superior scripting skills could write this up[calling a player sequence via weaponImage], I'd be happy to make a KORK DSQ that would demonstrate it...??! Would help a lot of folks out. I have a Ms3d KORK, that will produce content that is Drag/Dropable into any default Torque SDK, any takers?!?
02/03/2010 (5:36 am)
You need to setup the 'Visibility'[Frame# & Alpha level] of the mesh in question in the 'Meshes' section of the Exporter. You will need to activate the 'Edit' button to begin Mesh Editing[another dialog box].I think by default, all meshes should render[IE, visible] in all Frames of the Timeline; until you begin to attach an 'alpha' level to the meshes.
For example; say you have the Milkshape3D Timeline with 10 frames of animation, with all sequences separated and defined. Now, say your 'fire' sequence is 3 frames in length[doesn't matter where in the Timeline, just that the sequence and frames are defined], and falls on the last 3 frames[8,9,&10].
Now say you want your lovely muzzleFlash geometry[with alpha mask as well!] to only be visible for one single frame, say frame#2 of the 'Fire' sequence. This frame#2[actually Frame#9 of Timeline] will need to have a 'Visibility' matters array flag set. This is done by using the ADD button, then the Edit button[another popper appears], with a Frame and Alpha entry boxes. So, for this example, I would ADD 3 Visibility flags; entering "0" for Frame#8 and Frame#9, while entering "1"(or whatever transparency level you wish] for Frame#9. I would also create the Visibility flags in order of need, with Frame8 listed first, Frame9 next, and Frame10 last. Finish off with OK to close the Edit box, and you now 'should' have a Visibility Animation ready for export.
Since you only want this geometry to appear during 'Fire' and no other sequences in Timeline, you need to place the "0" Alpha value in the first frame of "Fire"; this 'should' keep that geometry 'invisible' until Frame9 of the Timeline, and then needs to be turned 'OFF' in Frame10.
Hope this helps.
PS: don't forget to set your Material transparency flag as well, if ya got/using one!
If someone with superior scripting skills could write this up[calling a player sequence via weaponImage], I'd be happy to make a KORK DSQ that would demonstrate it...??! Would help a lot of folks out. I have a Ms3d KORK, that will produce content that is Drag/Dropable into any default Torque SDK, any takers?!?
#16
02/03/2010 (11:24 am)
Thank you so much Rex, this is exactly what I was looking for! Thanks for all your help guys, I think I can finish my weapon now! :D
Torque Owner Daniel Buckmaster
T3D Steering Committee