- Home /
jump animation doesn't play all the way if i am moving
how can i just tap the jump key (space bar) and have my "jump animation" play all the way through while i am moving ?
this is my animation script,
function Start () {
}
function Update () {
if (Input.GetAxis("Vertical") > 0)
animation.Play ("jess walk");
if (Input.GetAxis("Horizontal") < 0)
animation.Play ("jess left");
if (Input.GetAxis("Horizontal") > 0)
animation.Play ("jess right");
if (Input.GetButton("Jump"))
animation.Play ("jess jump");
}
Answer by static_cast · Nov 11, 2013 at 01:03 AM
Hey, I think there this is your problem:
I think that because animations while you are pressing keys, which also have their own walking animations, they are overlapping the jump animation or stopping it all-together.
To fix this, you could...
allow the player to only move when they are grounded [this will disallow movement while jumping, of course],
or have a jump variable control whether or not they are jumping...
Here is code that you could use to get input movement, which I modified from my games [Which uses the first method, checking whether or not they are grounded, to determine whether or not they should move]:
#pragma strict
var movementSpeed = 1.0;
var jump : KeyCode;
private var x = 0.0;
private var z = 0.0;
private var grounded = true;
function Start()
{
rigidbody.freezeRotation = true;
}
function Update()
{
if(grounded)
{
x = Input.GetAxis("Horizontal") * movementSpeed * Time.deltaTime;
z = Input.GetAxis("Vertical") * movementSpeed * Time.deltaTime;
//Added this script
if(Input.GetAxis("Vertical") > 0)
animation.Play("jess walk");
if(Input.GetAxis("Horizontal") < 0)
animation.Play("jess left");
if(Input.GetAxis("Horizontal") > 0)
animation.Play("jess right");
//----
}
grounded = Physics.Raycast(transform.position, Vector3.down, 0.1);
transform.Translate(x, 0, z);
if(Input.GetKeyDown(KeyCode.Space) && grounded)
{
rigidbody.velocity = Vector3(0, Mathf.Sqrt(20), 0);
//And also this one
if(Input.GetButton("Jump"))
animation.Play("jess jump");
//----
}
}
Note: you will need your character to be a rigidbody [And have a collider] in order for this script to work.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
what is the jump axis for if (Input.GetAxis(" ? ") 2 Answers
Simple jump code? 2 Answers
Animation + Scripting = I Don't Understand (Help) 0 Answers
Unknown Identifier maxSlope 1 Answer