- Home /
Jump/FallDown animation plays only once
When I press the Jump key, the Jump animation clip plays, (and for some reason) the FallDown clip immediately after. However, when I press the Jump key again, nothing plays. What's causing this? Also, how do I make the FallDown clip play only when my character touches the ground after the Jump?
Here are my scripts (with some lines from the beginning/end of the script not necessary to show):
Controller:
//Move the controller during the fixed frame updates
function FixedUpdate()
{
if(!isControllable)
Input.ResetInputAxes();
else
{
if(grounded)
{
//Since we're touching something solid, such as the ground, allow movement
//Calculate movement directly from input axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= walkSpeed;
moveDirection.y -= gravity * Time.deltaTime;
//Find rotation based upon axes if need to turn
moveHorz = Input.GetAxis("Horizontal");
if (moveHorz > 0) //Right turn
rotateDirection = new Vector3(0, 1, 0);
else if (moveHorz < 0) //Left turn
rotateDirection = new Vector3(0, -1, 0);
else //not turning
rotateDirection = new Vector3(0, 0, 0);
//Jump controls
if(Input.GetButton("Jump"))
{
if(Input.GetButton("Run") && Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed/3;
}
else
{
moveDirection.y = jumpSpeed;
}
}
//Aplly any boosted speed
if(Input.GetButton("Run") && Input.GetAxis("Vertical"))
{
if(MoaliaStatus.stamina > 0)
{
isRunning = true;
if(MoaliaStatus)
{
moveDirection *= runSpeed;
MoaliaStatus.stamina -= MoaliaStatus.runUsage * Time.deltaTime;
isRunning = true;
}
}
else if(MoaliaStatus.stamina <= 0)
{
isRunning = false;
}
}
if(MoaliaStatus)
{
if(MoaliaStatus.stamina <= MoaliaStatus.maxStamina)
{
MoaliaStatus.stamina += MoaliaStatus.staminaRecharge * Time.deltaTime;
}
}
}
//Crouch the controller
if(Input.GetButton("Crouch"))
{
controller.height = crouchHeight;
controller.center.y = controller.height/2;
moveDirection *= crouchSpeed;
isCrouching = true;
}
if(Input.GetButtonUp("Crouch"))
{
//Reset height and center after ducks
controller.height = normalHeight;
controller.center.y = controller.height/2;
isCrouching = false;
}
if(Input.GetButtonUp("Run"))
{
isRunning = false;
}
//Apply gravity to end jump, enable falling, and make sure he's touching the ground
moveDirection.y -=gravity * Time.deltaTime;
//Move and rotate the controller
var flags = controller.Move(moveDirection * Time.deltaTime);
controller.transform.Rotate(rotateDirection * Time.deltaTime, rotateSpeed);
grounded = ((flags & CollisionFlags.CollidedBelow) != 0);
}
}
//----------------------------------------------------
function IsMoving()
{
return moveDirection.magnitude > 0.5;
}
function IsRunning()
{
return isRunning;
}
function IsCrouching()
{
return isCrouching;
}
function IsGrounded()
{
return grounded;
}
Animation:
function Update()
{
//On the ground animations
if(playerController.IsGrounded())
{
animation.Blend("FallDown", 0, 0.2);
animation.Blend("Jump", 0, 0.2);
//If Running
if(playerController.IsRunning())
{
animation.CrossFade("Run", 0.5);
animation["Run"].speed = 4.4;
nextPlayIdle = Time.time + waitTime;
}
else if(playerController.IsCrouching())
{
animation.CrossFade("Crouch", 0.2);
nextPlayIdle = Time.time + waitTime;
}
//Fade in Walk
else if(playerController.IsMoving())
{
animation.CrossFade("Walk", 0.5);
animation["Walk"].speed = 3.2;
nextPlayIdle = Time.time + waitTime;
}
//Fade out walk and run else
else
{
animation.Blend("Run", 0.0, 0.3);
animation.Blend("Walk", 0.0, 0.3);
animation.Blend("Crouch", 0.0, 0.3);
if(Time.time > nextPlayIdle)
{
nextPlayIdle = Time.time + waitTime;
PlayIdle();
}
}
}
//In air animations
else
{
if(Input.GetButton("Jump"))
{
animation.CrossFade("Jump");
}
if(!playerController.IsGrounded())
{
animation.CrossFade("FallDown", 0.5);
}
}
//Test for idle
if(Input.anyKey)
{
if(moveDirection.magnitude <= 0)
{
animation.CrossFade("Idle");
}
}
}
Update:
animation["Crouch"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Loop;
animation["Jump"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once;
animation["FallDown"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once;
Turns out that the Wrap$$anonymous$$ode was causing the Jump animation to play only when I press the Jump key the first time. So I changed it form ClampForever to Once. Yet, I still don't know how to fix the FallDown animation playing directly after Jump, when it should only play when my character is touching something solid.
Answer by CyberArtist · Aug 13, 2014 at 01:05 AM
Update:
Got rid of this:
animation.Blend("FallDown", 0, 0.2);
animation.Blend("Jump", 0, 0.2);
animation["FallDown"].speed = 3;
animation["Jump"].speed = 3;
Got rid of the remaining issues I was having.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Animation in Unity 4.3 0 Answers
Animation spins wildly after completed 0 Answers
How can I reassign animation curves to play on a child object (instead of through parent)? 1 Answer
Problem with animation: they always start at the same rotation!! 1 Answer