Jumping animation won't stop
So i am making a jumping animation that is working whenever i am jumping, but when i get to the ground it doesnt transit do "Idle" animation witch is just a sprite . I got all of those from a youtube video. It works ok but when is my character is grounded it isnt changing the bool value of transition. the condition on the transit from any state to jump is if IsJumping=True (this is working as intendet) here that youtube video told me to do this so i did.
public class TestScript : MonoBehaviour { //Declaring [SerializeField] private LayerMask lm; Animator animator;
public float moveSpeed;
public float jumpVelocity;
private Rigidbody2D rigidbody2d;
private BoxCollider2D boxCollider2d;
private void Awake()
{
animator = GetComponent<Animator>();
rigidbody2d = transform.GetComponent<Rigidbody2D>();
boxCollider2d = transform.GetComponent<BoxCollider2D>();
}
//Basic Movement
void PlayerMovement()
{
moveSpeed = 5f;
jumpVelocity = 500f;
//Right
if(Input.GetKey(KeyCode.D))
{
transform.position += Vector3.right * moveSpeed * Time.deltaTime;
}
//Left
else if (Input.GetKey(KeyCode.A))
{
transform.position += Vector3.right * -moveSpeed * Time.deltaTime;
}
//Jump
if(IsGrounded()&&Input.GetKeyDown (KeyCode.Space))
{
rigidbody2d.velocity = Vector2.up * jumpVelocity* Time.fixedDeltaTime;
animator.SetBool("IsJumping", true);
}
}
public void OnLanding()
{
animator.SetBool("IsJumping", false);
}
void Start()
{
}
void Update()
{
PlayerMovement();
}
//Jump helper
public bool IsGrounded()
{
RaycastHit2D raycasthit2d = Physics2D.BoxCast(boxCollider2d.bounds.center, boxCollider2d.bounds.size, 0f, Vector2.down , .1f, lm);
return raycasthit2d.collider != null;
}
}
Your answer
Follow this Question
Related Questions
Audio Issues with Animation + Grounded 0 Answers
How do you trigger an animation via script 0 Answers
Animation Running Game 0 Answers
Bool changes back instantly 3 Answers
Blender animations using multiple armatures not functioning properly 1 Answer