Handle movement and rotation myself

Hello, i’m currently having a problem with the movement.

I want the quadruped ai to align to the ground. This lead me to set updatePosition and updateRotation to false so that i can handle it.
However when updatePosition is set to false the following warning:

Path Failed : Computation Time 0.00 ms Searched Nodes 0
Error: Couldn’t find a node close to the start point

occurs every frame and the ai stays in place.

Docs:

bool updatePosition = true

Determines if the character’s position should be coupled to the Transform’s position.

If false then all movement calculations will happen as usual, but the object that this component is attached to will not move instead only the position property will change.

This is useful if you want to control the movement of the character using some other means such as for example root motion but still want the AI to move freely.

Such warning was not what i expected at all following the documentation.

Hi

If you are moving the character’s GameObject when your game starts, setting updatePosition to false would make the agent stay at its original position.
If you need to move the agent when updatePosition=false, use ai.Teleport instead.

Thank you for replying.

protected override void OnAwake()
{
    base.OnAwake();

    MovementState = MovementState.Walk;
    WasAttacked = false;
    WasCollided = false;
    IsChargeAttacking = false;

    AINavigator = GetComponent<RichAI>();

    AINavigator.isStopped = true;
    AINavigator.canSearch = false;
    AINavigator.enabled = false;

    AINavigator.updatePosition = false;
    AINavigator.updateRotation = false;

    AnimatorHandler = GetComponentInChildren<AnimatorHandler>();
}
protected override void OnUpdate()
{
    base.OnUpdate();

    if (ReachedDestination())
        return;

    // Calculate how the AI wants to move
    AINavigator.MovementUpdate(Time.deltaTime, out Vector3 nextPosition, out Quaternion nextRotation);

    SetMoveDirection(nextPosition);

    AINavigator.Teleport(GetMovementDirection());

    // Call base implementation (e.g. Default movement modes and states).
    Move();

    // Actually move the AI
    //AINavigator.FinalizeMovement(GetMovementDirection(), GetRotation());
}

I’ve tryied it all in several way, but the warning persists.

I need to control the movement as it conflicts when i change the rotation to align to the ground while moving towards the destination. But as soon i set the updatePosition to false it seems it’s impossible to make the ai to move.

A few days ago i tryied the example you provide in the docs for the MovementUpdate

void Update () {
    // Disable the AIs own movement code
    ai.canMove = false;
    Vector3 nextPosition;
    Quaternion nextRotation;
    // Calculate how the AI wants to move
    ai.MovementUpdate(Time.deltaTime, out nextPosition, out nextRotation);
    // Modify nextPosition and nextRotation in any way you wish
    // Actually move the AI
    ai.FinalizeMovement(nextPosition, nextRotation);
}

but when i try to align the character to the ground it moves waving (rotating) to left and right.
It seems it is conflicting the desired velocity, where i told the rotation should be, and the rotation it wants to be to move to the destination.

I’m trying to use it with easy character movement 2.
Any clue would really be appreciated!

Thank you.

Hello,

After all Teleport on Awake, did miracles.
Shuffling the order of rotation and movement was what i was missing.
I was also allowing the RichAI and my ai controller, to determine how to move the transform, and now only the RichAI determines how to move, and the ai controller just recieves that information and sets it.

Thank you very much once again.

1 Like