Game Development Community

Throwing and recoil animations

by Chris Oconnell · in Torque Game Engine · 03/03/2006 (2:40 pm) · 8 replies

In my projects, I'm trying to incorporate throwing weapons, as well as other weapons that would cause an unconventional firing/recoil movement from the player model. I've looked at numerous resources on melee combat. I just want a simple animation sequence to play when I shoot, but when I look at my player model in 3rd person, no matter what I do, I can't seem to get them to animate when the weapon is in it's onfire state. I haven't been messing with C++, just the scripts.
Any ideas?

Thanks ahead.

#1
03/03/2006 (4:22 pm)
Default engine code will override scriptset player animations if they are doing anything other than standing still and not moving. And what calls are you making to play the animations anyways?
#2
03/05/2006 (7:04 pm)
Wow, man... I've tried all sorts of stuff.
I've tried messing with binds to play a player animation along with fire if a certain weapon is selected, I've tried creating animation functions in player.cs and the weapon scripts to animate onFire... man, I've even tried copying snippits from Realmwars... nothing...
...but in all fairness to the TGE, I am probably the worlds worst scriptor. :P

If someone could just give me a point in the right direction to a proper way to just animate from a simple bind or function ...I bet I can figure it out.
#3
03/05/2006 (8:52 pm)
Hey Chris,

I'm a little confused about your original post. Without making any modifications to the engine you already have access to a type of animation on fire. Use the recoil system. There's nothing stopping you from making a recoil that breaks away from the conventional gun jolting back & forth animation.

Eg, for a grenade you could use an arm thread that puts the player's hands in a throwing position, and a recoil that was the animation of the arm throw.

You might find this resources useful, I know I did.

Adding Multiple Recoiling Animations for a single Player Model

Also, to set different arm threads for different weapons you'll need something like this in weapon.cs within the onMount function

if (%this.armthread $= "")
   %obj.setArmThread(lookms);
   else
   %obj.setArmThread(%this.armThread);

and in your weapons script, ie crossbow.cs, within the ShapeBaseImageData section

armThread = "lookms"; //or whatever you named it

Some other points of interest are:
First/Third Person Different Weapon Models

More Realistic First Person


This should get you going in the right direction. The recoil animations DO work in third person assuming you're doing everything correctly. Check out the Ork player in the demo, everytime he fires the crossbow his arms jolt back (as long as you specify a recoil within crossbow.cs).
#4
03/06/2006 (7:10 am)
...and remember: I believe with default flavour of TGE, this 'hack'[first post states NO C++ changes] will only work for 3 separate recoils. Light, Medium, and Heavy...choose your weapon'Styles' for recoils well......;). And I also 'think' that the recoil may end up running after the projectile is spawned and flying, just a little. They do 'probably' fire at the same time, but with a throwing 'action' animation sequence the arm moves before the 'launch' of the projectile.

It'll be interesting to see any workarounds here...:).
#5
03/06/2006 (7:36 am)
Hey rex,

That code isn't a hack in my opinion. It's a function that existed in Tribes2 & got broken in Torque somewhere along the line. I consider it more to be a fix. Also, it's very easy to duplicate the 'Light', 'Medium', 'Heavy' recoils into however many you want. For example, in our game we have those 3 standard recoils + several others like 'GrenadeRecoil' to accomodate for special weapons.

The recoil doesn't continue to play after the projectile is created, it only plays within the onFire state (or any other state you decide to declare a recoil).

Quote:
They do 'probably' fire at the same time, but with a throwing 'action' animation sequence the arm moves before the 'launch' of the projectile.

With some clever sripting & modelling a grenade throw is possible. Basically, in our game, we created a recoil which contains the arm throwing animation. This is played in the onFire state, when the arm is fully extended a projectile of the grenade is created, the grenade in the players hand's is deleted, and the grenade projectile takes over. Quite convining, you'd swear you were actually throwing a grenade.
#6
03/06/2006 (10:44 am)
Thanks, Tim. Sorry to sound, so...! How do you sync the projectile's creation at the end of the armThread recoil sequence?? I tried and tried to call an actionThread and other various methods to get them working...settled on the recoils as the only workable method...since they get called automagically by onFire. So, the armThread "throw" sequence stops when the projectile is created and we pass out of the Fire State??

My first attempt at a 'thrown' projectile was to examine the rocketlauncher of Tribes II...jizzled with the ballistic settings, and poof a fairly realistic thrown object[without the sequence...]. Projectile does funny stuf...with timed ignition, but a molotov cocktail instant explosion, looked great!.... With timed explosion, the projectile wobbles around on the terrain, sometimes spinning...
#7
03/07/2006 (3:14 pm)
Hey Rex,

I didn't think you sounded rude, just thought I should explain myself better.

Basically to sync the projectile I've created a non visible state in the animation (the fire sequence in the grenade weapon dts) that lines up with the end of the throw. The onfire function is delayed with a schedule that lines up with the arm being fully extended (about 3 seconds in my case). So when the players hand is fully extended, after the throw animation, the dts of the grenade in his hand disappears and the projectile is created.

As far as projectile bouncing and explosion problems, that's a new bug that made it to 1.4. These issues don't exist in 1.3.
#8
03/07/2006 (3:26 pm)
I know Torque supports animation triggers, so couldn't you create an animation of the grenade toss and trigger an event at the release point to actually throw the grenade? With that you can determine the position of the mount point and spawn the grenade there. I have never created an animation trigger so I couldn't tell you the whole process to do it but I know it could be done.