meisam s.b.
meisam s.b.

Reputation: 1

Animator controller does not transitioning even though parameter condition is met

I'm trying to transition from idle to attack when a boolean parameter is true.
my code does set the boolean parameter and I can see that it's set to true in the animator. but transition doesn't happen. while in playing mode once I change anything in the animator, suddenly transition works fine. this is my code.

public class Wraith : MonoBehaviour
{
    [SerializeField] GameObject projectile;
    [SerializeField] Vector3 projectilePosition;

    AttackerSpawner myLaneSpawner;
    Animator animator;

    void Start()
    {
        SetLaneSpawner();
        animator = GetComponent<Animator>();
    }

    void Update()
    {
        if (HasAttakerInLane())
        {
            animator.SetBool("shouldAttack", true);
        }
        else
        {
            animator.SetBool("shouldAttack", false);
        }

    }

and this is my animator controller. Animator controller schema

and transition settings

Update I get rid off exit time so only bool condition is required for transition and instead used the code below to make sure transition happens at a given time after idle animation played. now transition works fine.

void Update()
    {
        if (HasAttackerInLane() && animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.5f)
        {
            animator.SetBool("shouldAttack", true);
        }
        else
        {
            animator.SetBool("shouldAttack", false);
        }

    }

Upvotes: 0

Views: 1279

Answers (1)

Morion
Morion

Reputation: 10860

Several moments:

  • you have ExitTime enabled in your transition. It means that transition cannot start immediately
  • you are setting bool flag every update (many times per second), so it can easily become false right after was set to true

I suspect that you have the combo of these moments. Your flag becomes false earlier than your transition can begin.

Upvotes: 0

Related Questions