Hi there, new guy here, hehe I’ve been having a hard time figuring this animation stuff out, and was wondering if I could get some help with it; particularly with the scripting.
The script in question:
private var bodyMove : AnimationState;
private var wingFlap : AnimationState;
private var headTwitch : AnimationState;
private var attack : AnimationState;
private var die : AnimationState;
function Start ()
{
bodyMove = animation["bodyMove"];
wingFlap = animation["wingFlap"];
headTwitch = animation["headTwitch"];
attack = animation["attack"];
die = animation["die"];
// animation layer setup
bodyMove.layer = 1;
wingFlap.layer = 0;
headTwitch.layer = 1;
attack.layer = 2;
// configuring and starting up the animations
animation["bodyMove"].wrapMode = WrapMode.Loop;
animation.Play("bodyMove");
animation["wingFlap"].wrapMode = WrapMode.Loop;
animation.Play("wingFlap");
animation["attack"].wrapMode = WrapMode.Once;
animation["headTwitch"].wrapMode = WrapMode.Loop;
headTwitch.blendMode = AnimationBlendMode.Additive;
headTwitch.enabled = true;
headTwitch.weight = 0.75;
}
function Update ()
{
// Play the stinging animation whenever "T" is pressed.
// (I created an input in the project settings
// called 'stab' which is activated by the T key)
if (Input.GetButtonDown ("stab")) {
animation.Play("attack");
}
}
The thing being animated is a flying insect. The wingFlap animation is just that, his wings flapping, no other bones are touched. So that goes by itself, non-additively, and it plays with no problem. Then there’s the bodyMove, the insect bobs up and down, including his head, wings are not touched. This plays on the next layer. Again, so far no problem. Then there’s the the head twitch, added additively to the bodyMove’s animation layer, once again no trouble. All these loop constantly and compose the insect’s idle and basic movement.
Then we come to the problem; the attack animation. It plays on the next layer, non-additively but rather overriding the bodyMove animation, whenever the user presses the T key. Or at least, it’s supposed to. What happens is that the insect’s body movement animation gets completely halted for the duration the stinging motion is supposed to be, the stinging animation does not play, and then it resumes the body movement and goes back to normal. The wing flap, by the way, is unaffected, most likely because the other animations don’t use those bones at all.
But then, strangest of all, pressing T a second time yields the correct result! The body motion stops, the sting plays, and when the sting is done the body motion resumes as normal, and subsequent presses of T have it working perfectly.
It’s only that first time the T is pressed that it messes up, and this is where I’m getting confused. I’m sure it has something to do with the order in which stuff is being executed, but I’m unable to figure it out. Any help or advice on this (or perhaps a different, better method to do this) would be greatly appreciated. If any more info on what’s supposed to be happening is needed, please ask.[/code]