- Home /
Duplicate Question : http://answers.unity3d.com/questions/681305/how-to-get-jump-animation-to-play.html
How to get jump animation to play?
Ok so i have my basics in running and idleing working but now that i have got to jumping the animation just won't play. It either will do nothing (other than moving the character controller up and down for the jump) if my character is standing still and if he is moving it will play a very jittery version of the running animation.
Here is my code and the jump function is found at the bottom:
pragma strict
var runSpeed : float = 50; var rotationSpeed : float = 10; var gravity : float = 50; var body : Transform; private var xRot : float;
function Update () { var animation : Animator = GetComponent(Animator); var Controller : CharacterController = GetComponent(CharacterController); var Vertical : Vector3 = transform.TransformDirection(Vector3.forward); var Horizontal : Vector3 = transform.TransformDirection(Vector3.right); var Height : Vector3 = transform.TransformDirection(Vector3.up);
if (Input.GetKey("space")){
Jump();
}
if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")){
animation.Play("Run");
Controller.Move((Vertical * (runSpeed * Input.GetAxis("Vertical")) * Time.deltaTime));
Controller.Move((Horizontal * (runSpeed * Input.GetAxis("Horizontal")) * Time.deltaTime));
}else{
animation.CrossFade("Idle",0.2);
}
if(Input.GetAxis("Mouse X")){
xRot += 10 * Input.GetAxis("Mouse X");
transform.rotation = Quaternion.Euler(0,xRot,0);
}
Controller.Move(Height * gravity * Time.deltaTime);
}
function LateUpdate(){
if(Input.GetAxis("Horizontal") > 0 && Input.GetAxis("Vertical") > 0){
body.localEulerAngles.y = 135;
}else if(Input.GetAxis("Horizontal") > 0 && Input.GetAxis("Vertical") < 0){
body.localEulerAngles.y = 225;
}else if(Input.GetAxis("Horizontal") < 0 && Input.GetAxis("Vertical") < 0){
body.localEulerAngles.y = 315;
}else if(Input.GetAxis("Horizontal") < 0 && Input.GetAxis("Vertical") > 0){
body.localEulerAngles.y = 45;
}else if(Input.GetAxis("Vertical") > 0){
body.localEulerAngles.y = 90;
}else if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = 180;
}else if(Input.GetAxis("Vertical") < 0){
body.localEulerAngles.y = 270;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = 0;
}
}
function Jump(){ var animation : Animator = GetComponent(Animator);
animation.Play("Jump");
gravity = 60;
yield WaitForSeconds(.3);
gravity = -50;
}
Follow this Question
Related Questions
I need some help with AI 0 Answers
When character stops moving - stop "Walk" animation 1 Answer
Can the animation editor create local rotational data? 3 Answers
cannot get animation to play 3 Answers
Adding animation clips via script 2 Answers