Author Topic: Randomly cycling through attack animations?  (Read 2567 times)

see, i'm working on a melee weapons pack, and each weapon has three or four different attack animations that do exactly the same thing



is it possible to make it so that, when the weapon is used, it cycles randomly through the possible attacks, and then plays one animation?

Completely untested, but I can't see where it'd go wrong as I use a similar method:
Code: [Select]
datablock ShapeBaseImageData(yourWeaponImage)
{
...

stateName[#] = "FirePick1A";
stateScript[#] = "onFirePick";
stateTimeoutValue[#] = 0.01;
stateTransitionOnTimeout[#] = "FirePick1B";

stateName[#] = "FirePick1B";
stateTransitionOnAmmo[#] = "FirePick2A";
stateTransitionOnNoAmmo[#] = "FirePick3A";

stateName[#] = "FirePick2A";
stateScript[#] = "onFirePick";
stateTimeoutValue[#] = 0.01;
stateTransitionOnTimeout[#] = "FirePick2B";

stateName[#] = "FirePick2B";
stateTransitionOnAmmo[#] = "Fire1";
stateTransitionOnNoAmmo[#] = "Fire2";

stateName[#] = "FirePick3A";
stateScript[#] = "onFirePick";
stateTimeoutValue[#] = 0.01;
stateTransitionOnTimeout[#] = "FirePick3B";

stateName[#] = "FirePick3B";
stateTransitionOnAmmo[#] = "Fire3";
stateTransitionOnNoAmmo[#] = "Fire4";

stateName[#] = "Fire1";
stateSequence[#] = "Fire1";
//other fire stuff here

stateName[#] = "Fire2";
stateSequence[#] = "Fire2";
//other fire stuff here

stateName[#] = "Fire3";
stateSequence[#] = "Fire3";
//other fire stuff here

stateName[#] = "Fire4";
stateSequence[#] = "Fire4";
//other fire stuff here

};

function yourWeaponImage::onFirePick(%this,%obj,%slot)
{
%obj.setImageAmmo(%slot,getRandom(0,1));
}
Torque changes onAmmo/onNoAmmo states instantly when the state starts, so you have to use two for every change. This just picks a random state out of four - you'd then make give the animation four sequences called Fire1, Fire2, Fire3 and Fire4. Change the #s to fit in with your set of states. Give the fire states a timeout value 0.02 less than what you currently have it as to account for the picking states if you're using the armAttack animation as well to make sure it doesn't desynchronise. (e.g. fire when you're lifting the weapon up rather than bringing it down)

yeah, that didn't work-

Did you add it into your states and replace the hashes with numbers?

i followed your instructions more or less to the letter. it still didn't work properly, or at all


I thought it said "Randomly crying through attack animations"

And, no, not because I saw Bushido's name

This is relevant and helpful.

actually, i think i got rid of the code file.



could you put together an image datablock with the attack animations states?

I don't know what your weapon's attack threads or emitters/scripts needed are.

i can put that together, i just need an image datablock to screw with

What I gave you in the first post effectively is what you'd have as your states...

Add the "Activate", "Ready" and possibly "PreFire" states (with the sword) numbered before those ones, change PreFire's transition to go to FirePick1A and then give Fire1, Fire2, Fire3 and Fire4 the same attributes as the Fire state except for the stateSequence - this is your animation. Then put CheckFire and StopFire afterwards. Reduce the timeout value on the fire states by 0.02 to allow for the extra timers in my states.

With no information about the weapon I can't really give any more detail than this.