- Home /
 
 
               Question by 
               SuperHB · Nov 21, 2014 at 05:48 AM · 
                animationcharactercontrolleranimationsanimateanimating  
              
 
              Help with Custom Player Controller
Okay, so I'm working on my own Custom Player Controller and I'm having a few problems with the animations. What I'm trying to do is have this if statement check if the person is pressing down W and the code in the animation will call out to this variable (public var walkAnimation : AnimationClip;) which has the animation attached to it. When I start up the game it doesn't start as the idle animation, it starts half way through the walk animation... and frozen. When I make isIdle false the walk animation starts over, when I recheck isIdle it goes back the the half way frozen walk animation. Is this the correct way to do this? I'm kinda copying the code (In a more nooby way) from the Third Person Controller into my own JS Controller.
 #pragma strict
 
 //Adds Required Component to Game Object
 @script RequireComponent(null)
 
 //Identifier
 public var idleAnimation : AnimationClip;
 public var walkAnimation : AnimationClip;
 public var runAnimation : AnimationClip;
 public var sprintAnimation : AnimationClip;
 public var jumpAnimation : AnimationClip;
 public var strafeLeftAnimation : AnimationClip;
 public var strafeRightAnimation : AnimationClip;
 public var crouchAnimation : AnimationClip;
 public var crouchWalkAnimation : AnimationClip;
 public var crouchRunAnimation : AnimationClip;
 public var crouchStrafeLeftAnimation : AnimationClip;
 public var crouchStrafeRightAnimation : AnimationClip;
 
 //Animation Updater
 public var isIdle : boolean;
 public var isWalking : boolean;
 public var isRunning : boolean;
 public var isSprinting : boolean;
 public var isJumping : boolean;
 public var isStrafeLeft : boolean;
 public var isStrafeRight : boolean;
 public var isCrouched : boolean;
 public var isCrouchWalk : boolean;
 public var isCrouchRun : boolean;
 public var isCrouchStrafeLeft : boolean;
 public var isCrouchStrafeRight : boolean;
 
 //Energy Stuff
 public var canJump : boolean;
 public var canRun : boolean;
 public var canSprint : boolean;
 
 function Start () 
 {
     isIdle = true;
     isWalking = false;
     isRunning = false;
     isSprinting = false;
     isJumping = false;
     isStrafeLeft = false;
     isStrafeRight = false;
     isCrouched = false;
     isCrouchWalk = false;
     isCrouchRun = false;
     isCrouchStrafeLeft = false;
     isCrouchStrafeRight = false;
 }
 
 function Update () 
 {
     if(isIdle == true)
     {
         animation.Play(idleAnimation);
     }
     
     if(Input.GetKey(KeyCode.W) && isWalking);
     {
         //Enables walking animation
         animation.Play(walkAnimation);
     }
 }
 
              
               Comment
              
 
               
              Your answer