Override agent position with custom CC

Halo
I’m writing a hybrid ClickMove and WASD movement, and also using a custom CharacterController
Using RichAI and RVO
updatePosition false (custom move)

When pathfinding, updateRotation is true, and i feed my CC like so (pseudo code)
myCC.Move(agent.desiredVelocity);

I’m also turning off agent.gravity because the CC handles it

When moving down/upwards, this debug cylinder doesn’t follow
image

Setting gravity on in RichAI makes it follow, but the debug cylinder is still wrong sometimes
image

I’ve overrode the RVO with the real velocity result from the CC


        if(isServer)
        {
            if(!pathfinding)
            {
                rvo.velocity = velocity; // without this, the cylinder wont move at all when WASD
                rvo.rvoAgent.Position = transform.position;
            } else
            {

                rvo.rvoAgent.ElevationCoordinate = controller.GetFootWorldPosition().y;
            }
        }

But i think this is for the RVO and not the agent. In fact, rvo.rvoAgent.Position already follows agent’s position in RVOController.UpdateAgentProperties callback
I think overriding rvo.velocity is correct (when WASD), but the position overriding should be done to the agent, but… i’m not sure how to do that?
agent.position can’t be set, and it points to transform.position if updatePosition is true. But, i don’t want updatePosition…

I seem to be really close here. Everything works until i try to navigate downwards, then upwards through another route (crossing the cliff) when the pathfinding just tries to walk straight over the cliff, on which the CC fails due to slope (obviously). The fail move from the CC causes de-sync to the agent’s position over time…

Cheers

Hi

I would recommend that you just completely disable the RichAI and RVOController components when you are using WASD. Then you can enable them again when you need click to move behaviour.
Make sure you are modifying the position of the same object that the RichAI component is attached to.

You may also be interested in https://arongranberg.com/astar/docs/iastarai.html#MovementUpdate

Yeeees it works! Super awesome!
Right now i’m doing (pseudo)

agent.UpdateMovement(out nextPos, out nextRot);
if(!pathfinding)
     agent.FinalizeMovement(transform.position, transform.rotation);
     rvo.velocity = controller.realVelocity;
else
     moveVector = agent.desiredDir + some other adjustments
     myCC.Move(moveVector);
     agent.FinalizeMovement(transform.position, nextRot);

Although, you recommend disabling RVO when WASD?
But i want other pathfinding units (monsters included) to also consider the WASD-ing player.
What’s the big deal if i may ask?
Because it’ll probably gonna be a few more days until i actually test with many monsters/multiple player units mixing WASD/ClickMove etc…
Cheers

You can include a player controlled character in the simulation by setting the RVOController.velocity property every frame to whatever velocity your WASD movement script decides.

It looks like you are already doing that though :stuck_out_tongue:

1 Like