Game Development Community

Need Help - 'Unmount' for weapons

by Nicolai Dutka · in Torque Game Engine Advanced · 03/08/2010 (5:56 pm) · 18 replies

I see there is some code for weapons to 'unmount', but how do I call a state change on the weapon image?

I added to my weapon's CS file:
//Unmount
   stateName[7]                     = "Unmount";
   stateTimeoutValue[7]             = 0.5;
   stateSequence[7]                 = "Deactivate";

But I don't know how to tell the weapon to transition to state 7... I have a 'deactivate' animation I want played when the player unmount's their weapon.

Any help is much appreciated!

#1
03/08/2010 (6:17 pm)
Try giving the weapon's FSM a script to work from (like onFire works) and unmount the weapon from there.

eg:
//.....
statescript[7] = "OnUnmount";
//.....

function Weapon::OnUnmount(%this, %obj, %slot)
{
%obj.unmountImage(%slot);
}
#2
03/08/2010 (6:29 pm)
Ok but, I need the weapon itself to play an animation when it is unmounted. My game is in first person view. Using that code, the weapon just disappears. I wanted an animation of the weapon being "put away" by just having it move off screen.

I did a $player.dump and looked for 'setImageState', but the player doesn't have that option. I tried $weapon.dump to see if there are any functions available that would let me just play an animation on the weapon the same way i do on the player and still no luck:

$weapon.playThread(0,"Deactivate");

That would be really nice... Then I could run other animations on the weapons at any time I want...


Now that I think about it, I could use an invisible cube for my 'code weapon' and then also mount a static shape object to the same slot and use that as my 'visible weapon'. Then, I'd be able to play any animation on it I want, any time I want... Hmmm... I like being smart!

Thanks for the epiphany! :)
#3
03/08/2010 (6:47 pm)
stateSequence[7]                 = "Unmount";

You know if you export the animation sequence inside of your weapon, you can have it automatically called by using in the weapon's FSM with your animation name being the same as "stateSequence".
#4
03/08/2010 (9:49 pm)
Quote:
ou know if you export the animation sequence inside of your weapon, you can have it automatically called by using in the weapon's FSM with your animation name being the same as "stateSequence".

Exactly what I really wanted from the beginning, but can't figure out how to tell the weapon to enter state 7! I don't understand how to tell it to switch states manually...


I'm wanting to make it enter state 7 when i push a button on my keyboard to 'put away' the weapon, but I don't know what 'stateTransition' methods are available. For many I see "stateTransitionOnTimeout" and some have "stateTransitionOnTriggerDown" and just recently after lots of forum surfing for this issue, I found one none of my weapons have: "stateTransitionOnTriggerUp".


All I want is to press a button on my keyboard and have my weapon play an animation....
#5
03/09/2010 (2:28 am)
I had a similar post the other day and Rene said that is no way (without changing source code) to set ImageState. Anyone know more about this?

Edit: ahhh, you can't read the private forums. Do'h. Here is the quote:
Quote:Headline: Anyone knows how i can set a weapon state?
Quote:Rene Damm: None that I'm aware of, though you could probably easily add this by exposing ShapeBase::setImageState to script.
#6
03/10/2010 (1:33 pm)
I've seen resources available that walk you through doing that very thing and was hoping to avoid it, but looks like Torque decided people don't need to put weapons away so I have little choice...
#7
05/29/2010 (3:10 pm)
I am working on part of this for a class project. What I have noticed, is that each state might have a link to the next state.

in state 0:
stateTransitionOnLoaded[0] = "Activate";

in state 1:
stateName[1] = "Activate";
stateTransitionOnTimeout[1] = "Ready";

in state 2:
stateName[2] = "Ready";
stateTransitionOnTriggerDown[2] = "Fire";

in state 3:
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Reload";

in state 4:
stateName[4] = "Reload";
stateTransitionOnNoAmmo[4] = "NoAmmo";

in state 5:
stateName[5] = "NoAmmo";
stateTransitionOnTriggerDown[5] = "DryFire";

in state 6:
stateName[6] = "DryFire";
stateTransitionOnTimeout[6] = "NoAmmo";

Here in state 6, it links back up to NoAmmo state 5. I'm wondering if we change it to point to state 7, we might get the link?

stateTransitionOnTimeout[6] = "Unmount";
in state 7:
stateName[7] = "Unmount";
#8
05/29/2010 (3:38 pm)
Well, linking the DryFire state to the Unmount state will only make the Unmount script get called whenever running out of ammo (which might be the result someone would want), in this thread we where trying to achieve a way to set state through function.

The fact that all the states are linked is because the states have spesific functions; For example
State 1:
stateTransitionOnTimeout[1] = "Ready"; this means that when the state times out, it will move on to the state named ready. The point with this state is to play the animation declared in the state, stateSequence[1] = "Activate"; while the state is active.

State 2:
stateTransitionOnTriggerDown[2] = "Fire"; this means that the state will not change before "TriggerDown"/left click. It will lead you to the state fire which calls the fire script.

There is a system in the weapons state definision, which in many cases can be exploited, but not in this case.
#9
05/29/2010 (3:39 pm)
Quote:in state 6:
stateName[6] = "DryFire";
stateTransitionOnTimeout[6] = "NoAmmo";

Here in state 6, it links back up to NoAmmo state 5. I'm wondering if we change it to point to state 7, we might get the link?

stateTransitionOnTimeout[6] = "Unmount";
in state 7:
stateName[7] = "Unmount";

This would make the weapon unmount when you 'dry fire' (fire with no ammo). If that's what you want....

Personally, I implemented a resource I found that allows me to manually unmount the weapon by binding a function to my keyboard. Press the button and the weapon 'gets put away' (animated and all)
#10
05/29/2010 (3:50 pm)
Hmm, ok. Perhaps in another part of the state script, maybe inserted in the right spot it might make more sense. I was hoping to get the weapon put away as soon as it ran out of ammo, so the player knew it was empty and would not try to use it, getting a dry fire when targeting a bad guy.
#11
05/29/2010 (3:56 pm)
If thats what youre trying to achieve you can try to add a stateScript to the DyrFire state;

stateName[6] = "DryFire";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "NoAmmo";
stateSound[6] = RocketLauncherFireEmptySound;
stateScript[6] = "onDryFire"; // <- Here
and then making the %weaponimage%::onDryFire(); function to change the weapon to the next one.
#12
05/29/2010 (3:57 pm)
If all you want is to go from no ammo to unmount:

stateName[5] = "NoAmmo";
stateTransitionOnTimeout[5] = "Unmount";

stateName[7] = "Unmount";


You'll also need a function run on state 7. I forget the exact code but something like:

stateScript[7] = "onUnmount";

And lastly, a new function for your weapon:

Weapon_Image::onUnmount(%this,%obj)
{
//play animation
}


Then your function could play an unmount animation. The weapon would stay equipped, but would be out of sight, holstered.
#13
05/29/2010 (3:59 pm)
Lol, Marcus... Great minds think alike. ;)
#14
05/29/2010 (4:00 pm)
Where just about to EDIT my comment to say that, haha
#15
05/29/2010 (4:04 pm)
Ok, thanks. Will try that.

Works nice, thanks guys.
#16
11/16/2010 (9:23 am)
Older topic I know, BUT:

I have "jumping" and "running" etc. anims for my weapons that I want to tie into player movement. I assume I need to use the same method as above ?

TBH, I've always thought that the state machine functionality needed updating for T3D.
#17
11/17/2010 (11:23 pm)
Note: I have not done this myself so what i say may not be possible nor easily doable.
Well, depends, there are three ways as far as i see;
1) If you mix arms and weapon in the same weapon item you can use states to animate jumping, running, shooting ect. in the same model.
2) If you are going for separate arms and weapon you'll have to synchronize arm animations with the weapons state anim.
3)*this method is questionable!* If you are going for separate arms and weapon and you're trying to avoid the synchronizing, i think you can animate the mount point in the players anim to match what you'd have in your weapons anim.

Quote:TBH, I've always thought that the state machine functionality needed updating for T3D.
Agreed, but really i think TP has other stuff to think about ATM =/.
#18
11/18/2010 (3:45 pm)
Thanks for the reply! :-)

My weapons and arms are all part of the same DTS so no problems there. I'm just struggling to see how I can tie them into the state machine. I'll keep plugging away at it for now - but it would be useful to see a working example beyond the very simplistic standard setup!


Cheers!