Hey Guys, I’m new to Unity and still learning most of the basic stuffs. I was trying to make a movement script for my character and got stuck in animating its jump. The jump involves of three animations, “up”, “float” and “down”. In script, I created a float named “Height” which stores the ‘y’ position of the character when jump key (space) is pressed and respective to value of this variable the jump animations will blend.
(Note: I had manually set the threshold for blending for max height reached by character).
Now everything works fine but the problem arrives in first jump , that is when I press space (only once), It doesn’t play the “jump Up” animation but plays “float” and “down” animations. If I hold the jump key the problem occurs for the first jump only but after that it works fine.
script:
if (Input.GetKey (KeyCode.Space) && isGrounded)
{
isGrounded = false;
anim.SetBool ("run",false);
anim.SetBool ("walk",false);
rb.AddForce (jump * jumpForce, ForceMode.Impulse);
anim.SetBool ("jumping",true);
Height = transform.position.y - curHeight;
}
else
anim.SetBool ("jumping",false);
if (isGrounded == false)
{
anim.SetBool ("jumping",true);
if(Input.GetKey(KeyCode.W))
transform.Translate (Vector3.forward * runSpeed * Time.deltaTime);
Height = transform.position.y - curHeight;
Debug.Log ("Height = " + Height);
anim.SetFloat ("Height", Height);
}
I’m still new and still don’t much about Unity and I’m willing to learn. So any help or guidance will be much appreciated.