- Home /
Vector3.Lerp and Animations
So I have my weapon and a gun sway script but i also have some animations which are constantly playing (idle, walk, sprint, aim). I think that there is some issue with the animations overriding the vector3.lerp. If not then please tell me why this isn't working. But if anyone has any idea how to have the lerp and the animations that would be great. Here is the Code
 public var MoveAmount : float = 1;
 public var MoveSpeed : float = 2;
 public var Gun : GameObject;
 public var MoveOnX : float;
 public var MoveOnY : float;
 public var DefaultPos : Vector3;
 public var NewGunPos : Vector3;
 
 function start () {
     DefaultPos = transform.localposition;
 }
 
 function Update () {
 
     MoveOnX = Input.GetAxis("Mouse X") * Time.deltaTime * MoveAmount;
     MoveOnY = Input.GetAxis("Mouse Y") * Time.deltaTime * MoveAmount;
     NewGunPos = new Vector3 (DefaultPos.x+MoveOnX,DefaultPos.y+MoveOnY, DefaultPos.z);
     Gun.transform.localpostion = Vector3.Lerp(Gun.transform.localPosition, NewGunPos , MoveSpeed * Time.deltaTime);
 }
Sorry at the moment I am at school and do not have access to the code as soon as i get back i'll upload it here.
Here it is, this probably isn't the best way to do the animation but I wrote and figured this one myself so... yeah.
 var sprinting : boolean = false;
 var walking : boolean = false;
 var Player$$anonymous$$otor : Character$$anonymous$$otor;
 var SprintSpeed : float = 12;
 var WalkSpeed : float = 6;
 var PlayerController : CharacterController;
 var PlayerVelocity;
 var Ai$$anonymous$$g : boolean = false;
 
 //animation
 function Update () 
 {    
     //set player velocity the same as controller
     PlayerVelocity = PlayerController.velocity.magnitude;
     //check ai$$anonymous$$g
     if (Input.Get$$anonymous$$ouseButtonUp(1))
     {
         Ai$$anonymous$$g = false;
     }
     
     // see if walking is off
     if (Input.GetAxis("Vertical")== 0)
     {
         walking = false;
     }
     
     // see if walking is off
     if (Input.GetAxis("Horizontal")== 0)
     {
         walking = false;
     }
     
     //check if sprinting is off
     if (Input.GetButtonUp("Sprint"))
     {
         sprinting = false;
     }
     //if ai$$anonymous$$g is on
     if (Input.Get$$anonymous$$ouseButtonDown(1))
     {
         Ai$$anonymous$$g = true;
     }
         
     //check if walking is on
     if (Input.GetAxis("Horizontal"))
     {
         walking = true;
     }
     
     //check if walking is on
     if (Input.GetAxis("Vertical"))
     {
         walking = true;
     }
     //check if sprint is on
     if (Input.GetButtonDown("Sprint"))
     {
         sprinting = true;
     }
     
     //is ai$$anonymous$$g is on
     if (Ai$$anonymous$$g == true)
     {
         sprinting = false;
         animation["Ai$$anonymous$$gInIdle"].speed = 1+(PlayerVelocity/WalkSpeed);
         animation.CrossFade("Ai$$anonymous$$gInIdle", 0.4);
         //change speed
         Player$$anonymous$$otor.movement.maxForwardSpeed = WalkSpeed/0.8;
         Player$$anonymous$$otor.movement.maxBackwardsSpeed = WalkSpeed/2;
         Player$$anonymous$$otor.movement.maxSidewaysSpeed = WalkSpeed/1.5;
     }
     
     //if sprinting is on play anim
     else if (sprinting == true)
     {
         walking = false;
         animation["Sprint Animation"].speed = PlayerVelocity/SprintSpeed;
         animation.CrossFade("Sprint Animation", 0.2);
         //change speed
         Player$$anonymous$$otor.movement.maxForwardSpeed = SprintSpeed;
         Player$$anonymous$$otor.movement.maxBackwardsSpeed = SprintSpeed/2;
         Player$$anonymous$$otor.movement.maxSidewaysSpeed = SprintSpeed/1.5;
     }
     
     //if not check if walking is on if it is play anim
     else if(walking == true)
     {
         animation["Walking Animation"].speed = PlayerVelocity/WalkSpeed;
         animation.CrossFade("Walking Animation",0.3);
         //change speed
         Player$$anonymous$$otor.movement.maxForwardSpeed = WalkSpeed;
         Player$$anonymous$$otor.movement.maxBackwardsSpeed = WalkSpeed/2;
         Player$$anonymous$$otor.movement.maxSidewaysSpeed = WalkSpeed/1.5;
     }
     
     //if all are false then playu idle
     else 
     {
         animation.CrossFade("Idle Animation",0.3);
     }
 
 }
 
Your answer
 
 
             Follow this Question
Related Questions
Lerping Field Of View is buggy 1 Answer
Learning to move 1 Answer
How to make an Animation movement happen only after certain keyframes? 0 Answers
animating multiple weapons with 2 arms 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                