- Home /
Animation not transition from Crawl_Idle to Crawl_anim
The two parameters are Speed (float) and DownKeyPressed (bool). When I press the down key it should play Crawl_Idle (it is working). When I press Arrow keys player should move left or right and play the Crawl_anim (which is not getting played). If the speed is greater than 0.01 PlayerWalk is played. But in case of crawl if speed is greater than 0.01 Crawl_anim should play. The speed parameter's value is increasing and player is moving left or right but Crawl_anim is not getting played. The transistioning condition between playerindle and playerWalk is same as in between Crawl_Idle and Crawl_anim ,i.e., Speed. I have tried using different variables, it didn't work.
Here my player movement script :
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Player_Movement : MonoBehaviour
{
public float walkSpeed = 5f;
public float runSpeed = 10f;
public float crawlSpeed = 2f;
private float speed = 0;
private Vector2 movement;
private Animator animator;
private Rigidbody2D rb;
private bool facingRight = true;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
private void Update()
{
movement.x = Input.GetAxisRaw("Horizontal") * speed;
Crawl();
WalkRun();
}
private void FixedUpdate()
{
rb.velocity = new Vector2(movement.x,rb.velocity.y);
}
private void WalkRun()
{
if (Input.GetKey(KeyCode.LeftShift))
speed = runSpeed;
else speed = walkSpeed;
if (facingRight == true && movement.x < 0)
Flip();
if (facingRight == false && movement.x > 0)
Flip();
animator.SetFloat("Speed", Mathf.Abs(movement.x));
}
private void Crawl()
{
animator.SetBool("DownKeyPressed", Input.GetKey(KeyCode.DownArrow));
if (animator.GetBool("DownKeyPressed") == true)
{
speed = crawlSpeed;
}
}
private void Flip()
{
facingRight = !facingRight;
Vector3 scalar = transform.localScale;
scalar.x *= -1;
transform.localScale = scalar;
}
}
Some images of animator :
Your answer
Follow this Question
Related Questions
How to access and modify an animator state transition in runtime? 1 Answer
Transitions from blend tree never work 0 Answers
Why does my animation clip play fine in the blend tree but not in the transition? 1 Answer
Bug animation transitions, or am I the bug? 0 Answers
How to deal with the Transitions If I have ten or more kinds of Animations in Unity Animator? 0 Answers