Rigidbody, AIPath and Update

Hi, I use the AIPath (derived class) and I had used a CharacterController for the player. Now I want to change to Rigidbody but I have the feeling that the implementation of AIPath is wrong. The AddForce is applied in the Update-function. In my opinion it should be added in the FixedUpdate, right? Is there an example implementation for AIPath using Rigidbody in this way?

Regards, Matthias

Now I use this method to move with RigidBody which works quite well:

`
protected new void FixedUpdate()
{
//Get velocity in world-space
Vector3 velocity = Vector3.zero;
if (canMove)
{
//Calculate desired velocity
Vector3 dir = CalculateVelocity(GetFeetPosition());

    //Rotate towards targetDirection (filled in by CalculateVelocity)
    RotateTowards(targetDirection);

    dir.y = 0;

    if (dir.sqrMagnitude > sleepVelocity * sleepVelocity)
    {


    }
    else
    {
        //Otherwise, just stand still (this ensures gravity is applied)
        dir = Vector3.zero;
    }

    if (navController != null)
    {
        velocity = Vector3.zero;
    }
    else if (controller != null)
    {
        controller.SimpleMove(dir);
        velocity = controller.velocity;
    }
    else if (rigid != null)
    {
        rigid.velocity = dir;
        velocity = rigid.velocity;
    }

    Vector3 relVelocity = tr.InverseTransformDirection(velocity);
    relVelocity.y = 0;

    if (relVelocity.sqrMagnitude <= sleepVelocity * sleepVelocity)
    {
        // Do animation (run)
        PlayerController.Instance.DoIdle();
        audio.Stop();
    }
    else
    {
        // stop animation
        PlayerController.Instance.DoMove();

        if (!audio.isPlaying)
        {
            audio.Play();
        }
    }

}
else
{
    velocity = Vector3.zero;
}

}
`

These are the problems:

  1. When the player is colliding an object that is in the way, the animation does not stop. I thought of addign an OnCollision method but perhaps there is a better way?

  2. Gravity is not applied like in the ChcracterController, perhaps you can help me with that?

Kind regards

Matthias