Animation Controller with RichAI

Hey

So i am trying to work out how to implement my animation controller to my RichAI stuff.

So i have just set up this bit of script to test my animations using RichAI:

protected override void Update()
{
    Debug.Log(Velocity.x);
    if (Velocity.x == 0f && Velocity.z == 0f)
    {
        animator.SetBool("Walking", false);
    }
    else
    {
        animator.SetBool("Walking", true);
    }
    base.Update();
}

My issue is when the character reaches his destination for the last second or two, hes walking on the same spot as the position is micro-adjusting to get to his destination. You can see it in this image, it looks like hes being “pushed”:

Other times he will walk on the spot indefinitely so i am confused by how the velocity data works if it never reaches 0.

Am i going about animation implementation wrong? What is the right way to implement RichAI with animation controllers ?

The example projects uses components which are out dated for Unity 5 so it’s quite tricky to understand.

Hi

I would suggest a higher threshold. This is how it is usually done:

animator.SetBool("Walking", Velocity.magnitude > 0.2f);

Where 0.2 is just some constant, you might want to increase it or reduce it.
This will make it stop walking when those micro adjustments are done.

On the RichAI component you can also increase the ‘endReachedDistance’ to stop it completely sooner.

1 Like

So i tried this but it was still animating i couldn’t work out why but then i checked this:

protected override void OnTargetReached() { Debug.Log(Velocity.magnitude); }

And it always gives a number like : 2.991099

Which doesn’t seem to make much sense since hes not moving he should be giving 0f as a result. Is this a bug or intentional, or am i misunderstanding something?

Right, that includes gravity so you might want to project that down to the XZ plane.
Also, I remembered that you are using RVO, this velocity does not include RVO calculations (it is the desired velocity of the agent), so the best way for you to get the velocity would be

GetComponent<RVOController>().Velocity

The RVOController does not care about gravity, so this should be fine.
I think it should work fine in the beta that you are using, otherwise just ping me.

1 Like

Awesome, just what I was looking for!

1 Like