Game Development Community

Play animation on Attack/Fire

by Scottie Sirius · in Technical Issues · 11/05/2009 (1:40 pm) · 7 replies

I'm trying to get an AI to throw a bomb at players and have a couple questions.
1. Where do you go to set a specific animation to play upon fire?
2. If I used the built-in HandBomb, how would I get the AI to fire it vs using the 'G' Key?

#1
11/05/2009 (1:54 pm)
1. OnFire() function in the weapon's cs controls what happen when it fires, also check out the "fire" part of the FSM that controls the weapon. It's where animations (for the weapon) gets called. If you want the weapon's owner to animate, onFire is probably the place you'd want to call it.

2. Script conditions in the AI's thought process for it. If it doesn't have a logical reason to do something, then it's not going to.

Things to think about:
Is there a target?
Is the target in range?
Is the LOS clear to the target?
If yes to all the above, fire weapon, player animation, etc
#2
11/05/2009 (2:56 pm)
What's an FSM?

I don't see an OnFire function in the rocketLauncher.cs...I see this:

// Fire the weapon. Calls the fire script which does the actual work.
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "PostFire";
stateTimeoutValue[3] = 0.9;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateSound[3] = RocketLauncherFireSound;
stateEmitter[3] = RocketLauncherfiring1Emitter;
stateEmitterTime[3] = 0.6;
#3
11/05/2009 (4:04 pm)
"That" is an FSM - or at least the third [3] part of it.

StateScript[3]="onFire";

Script is the hint -> scripts/server/theweapon's.cs file. Where stuff that happens when onFire is called, like spawning a projectile, etc.
#4
11/05/2009 (4:33 pm)
Yep, I read that whole article on Finite-State Machines on Wikipedia.
For some reason it didn't get my AI to do his Throw animation...lol.

Any examples of weapon.cs where a player animation is actually called?
#5
11/05/2009 (4:52 pm)
I don't think that there are any stock examples of this.

You want to get the object the weapon is mounted on, and call some type of animation on that. There are a few different types of animation, playthread, playcel, I'm not certain what they all do. Maybe call a dump on a shapebase weapon image to get the available functions for all of this. They might be listed in Torsion.

Or you could just cheat and use name_or_ID.playthread(0, "youranimation"); at the same time your AI pulls the trigger in your AIplayer.cs. But the first way is surely the more aesthetic.
#6
11/13/2009 (2:33 pm)
by naming his throw/attack sequence light_recoil:

i.e. - sequence12 = "./goblin_attack01.dsq light_recoil";
to coincide with this in the bomb.cs file
stateRecoil[3] = LightRecoil;

he seems to be throwing the bomb now but...he plays the animation twice for every 1 throw. I'm not sure how to adjust this so it looks a little more realistic. Any thoughts?

EDIT: Found it, I'm using the Improved AIGuard Kit so in scripts/server/aiplayer.cs adjust:

//How long the bot waits between firing bursts.
$AISK_FIRE_DELAY = 10000;

I went from 1000 to 10000 and it seems to line up about right.
#7
04/03/2010 (11:16 am)
I'm getting back to this and now and trying to get it to look better. The problem I'm having is that this is a recoil animation and happens 'after' he fires every time. Isn't there a Fire animation or a simple way to make one in the state machine so it coincides with firing the projectile/bomb/grenade?