x


Scripting-Animation Issue

In the prototype I'm working on, I have it so the space bar makes the character jump and the Fire1 button makes the character perform a random attack (out of the two I have animated). The movement controls are the typical W,A,S,D setup and the Fire2 button can orbit the camera around your character.

I've gotten the crossfades to work nicely while holding down the appropriate keys to move the character forward, backward, pivot left, and pivot right (I haven't restricted them to stop the pivot animations from playing while running and turning just yet, but that will be for later. I also have two attack animations, and a temporary jump animation. I'm still messing with the jump animation for it's timing at the appropriate parts of the jump, so for the time being, it's just supposed to play the whole thing at the standard frame-rate.

The issue is that while the W,A,S,D buttons require to be held down to loop through their animations and crossfade back to idle while they're not being held down, the space bar and Fire1 are supposed to just continue playing after the click or touch, but they don't. Regardless if I use GetButtonDown or GetButton, I get the same result. Any suggestions?

for (var i: KeyCode in zikkuKeys)
    {
       if(Input.GetKey(i))
       {
         switch(i)
         {
          case KeyCode.W:
              PerformSomething(ZikkuState.Running);
          break;
          case KeyCode.A:
              PerformSomething(ZikkuState.PivotLeft);
          break;
          case KeyCode.S:
              PerformSomething(ZikkuState.MoveBackwards);
          break;
          case KeyCode.D:
              PerformSomething(ZikkuState.PivotRight);
          break;
          case KeyCode.Space:
              if(canJump == true)
              {
                 PerformSomething(ZikkuState.Jumping);
              }
          break;
         }
       }
       if(Input.GetButtonDown("Fire1"))
       {
         PerformSomething(ZikkuState.Attacking);
       }
       else if(!Input.anyKey)
       {
         PerformSomething(ZikkuState.Idle);
       }

And here's the function Perform Something that explains what each acceptable input does.

function PerformSomething(currentState : ZikkuState)
{
    movePlayer = (Vector3.forward*Time.deltaTime);
    turnPlayer = (Vector3.up*Time.deltaTime);

    switch(currentState)
    {
       case ZikkuState.Idle:
         zikkuChar.animation.CrossFade("idle", 0.2);
       break;
       case ZikkuState.Running:
         transform.Translate(movePlayer * runSpeed);
         zikkuChar.animation.CrossFade("run", 0.2);
         zikkuChar.animation.wrapMode = WrapMode.Loop;
       break;
       case ZikkuState.MoveBackwards:
         transform.Translate(-movePlayer * moveBackSpeed);
         zikkuChar.animation.CrossFade("moveBackward", 0.2);
         zikkuChar.animation.wrapMode = WrapMode.Loop;
       break;
       case ZikkuState.PivotLeft:
         transform.Rotate(-turnPlayer * turnSpeed);
         zikkuChar.animation.CrossFade("pivotLeft", 0.2);
         zikkuChar.animation.wrapMode = WrapMode.Loop;    
       break;
       case ZikkuState.PivotRight:
         transform.Rotate(turnPlayer * turnSpeed);
         zikkuChar.animation.CrossFade("pivotRight", 0.2);
         zikkuChar.animation.wrapMode = WrapMode.Loop;
       break;
       case ZikkuState.Jumping:
         lastJumpButtonTime = Time.time;
         zikkuChar.animation.CrossFade("JumpTemp", 0.2);
         zikkuChar.animation.wrapMode = WrapMode.Once;
         print("Zikku jumped.");
       break;
       case ZikkuState.Attacking:
         ZikkuAttacks();
       break;
       default:
         zikkuChar.animation.CrossFade("idle", 0.2);
       break;
    }
}
more ▼

asked Feb 20 '12 at 03:24 AM

Zikku gravatar image

Zikku
20 2 5 8

It was later discovered that my last else if statement was what was doing it. I had to change it to look to see if any other state was false before setting idle to true.

Sep 25 '12 at 05:12 PM Zikku
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3460
x237
x18
x17

asked: Feb 20 '12 at 03:24 AM

Seen: 362 times

Last Updated: Sep 25 '12 at 05:12 PM