- Home /
 
               Question by 
               Enodman123 · Oct 04, 2013 at 09:41 PM · 
                animationplayergun movement  
              
 
              Transition to sprint animation not working
So far, my animations form idle to walking and back are good. But as soon as i hit "Sprint," its seems to merge its position with some other position (IDK where, it's out a bit from where I need it). This is my code:
 var gunAnimations : Animation;
 var gun : GameObject;
 var player : GameObject;
 var playerState : int = 0;
 var fadeLength : float = 1;
 @HideInInspector
 var smoothDampV : float;
 @HideInInspector
 var headBobScript : HeadBobScript;
 
 function Awake ()
 {
     headBobScript = GameObject.FindWithTag("MainCamera").GetComponent(HeadBobScript);
     
 }
 
 function Update ()
 {
     if (!Input.GetButton("Fire2"))
     {
         gameObject.animation.enabled = true;
         PlayerStateController();
         PlayerAnimationController();
     }
     else
     {
         gameObject.animation.enabled = false;
         transform.localPosition.x = Mathf.SmoothDamp(transform.localPosition.x, 0, smoothDampV, 0.05);
         transform.localPosition.y = Mathf.SmoothDamp(transform.localPosition.y, 0, smoothDampV, 0.05);
         transform.localPosition.z = Mathf.SmoothDamp(transform.localPosition.z, 0, smoothDampV, 0.05);
     }
     print(playerState);
 }
 
 function PlayerStateController ()
 {
     if (player.GetComponent(PlayerMovementScript).grounded)
     {
         if ((Input.GetAxis("Horizontal") || Input.GetAxis("Vertical")) && !Input.GetButton("Sprint"))
             playerState = 1;
         
         else if ((Input.GetAxis("Horizontal") || Input.GetAxis("Vertical")) && Input.GetButton("Sprint"))
             playerState = 2;
             
         else if (!Input.GetAxis("Horizontal") || !Input.GetAxis("Vertical"))
             playerState = 0;
     }
 }
 
 function PlayerAnimationController ()
 {
     if (playerState == 0)
         gunAnimations.CrossFade("idle", fadeLength);
         
     else if (playerState == 1)
     {
         gunAnimations.CrossFade("walking", fadeLength);
         gunAnimations["walking"].speed = player.rigidbody.velocity.magnitude;
     }
     
     else if (playerState == 2)
     {
         gunAnimations.CrossFade("sprinting", fadeLength);
         gunAnimations["sprinting"].speed = player.rigidbody.velocity.magnitude;
     }
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
How to replace 3rd person mesh with my own? 0 Answers
Jump animation anticipation 2 Answers
Rotating arm with Animation Event 1 Answer
Making FPSController Stagger 0 Answers
Why won't my animation play? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                