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");
}
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.