Agents unexpectedly teleporting

I’ve got agents that randomly wander around on a recast graph. The recast graph is evaluated (using graph update objects) at runtime in chunks, in case that may provide insight.

These agents use a RichFunnel, and constantly call funnel.ClampToNavmesh on their position, to ensure they don’t stray off.

What seems to be happening though, is that occasionally they’ll just teleport from location to location. I’ve confirmed the jump is happening within ClampToNavmeshInternalFull, usually with a distance of 5-15m or so (between the input Vector3, and the output Vector3).

I’ve added some logs to get a bit more information generated within that method. closestIsInPath is usually true, but not always. The graph is always the same (I only have one graph).

I’m completely stumped on this one, and have spent hours trying to debug the issue. Whenever an agent teleports by this bug, it is to another point on the navmesh; it’s not into the air, or into walls. It also often seems to teleport back to the same points, though that could simply be due to limited space.

I’ll continue looking into this tomorrow, but thought I’d drop a query here in case it’s a problem with an easy solution or debugging strategy.

Cheers,
Joel

Hi

Are you using a custom movement script for this?

Damn, speedy reply!

I believe I am. I can not remember if it was based on any particular demo script. It basically uses MovementUtilities.CalculateAccelerationToReachPoint to evaluate acceleration, and MovementUtilities.ClampVelocity to clamp the velocity. It then adds that velocity to the position and runs this clamp to the navmesh, before applying it back to the agent.

The code is naturally a fair bit more verbose than that, though I can post if helpful.
The distinct jump comes from within the ClampToNavmesh though. It should never be the case in my scene for the ‘nearest point on the navmesh’ to be so far away.

The ‘Walker’ class which moves the agent around has been used for most creatures in this game for the past couple years with absolutely no changes made recently. The only new aspects is the ‘chunk by chunk’ navmesh generation in this area.

The bounds of each generated ‘chunk’ should perfectly align with each other, but I still wonder if the RecastGraph will properly have ‘stitched’ them up.

Do you think the teleport happens when the path has just been recalculated?

These agents evaluate a target and walk to it, stop for a while, before choosing a new target.
It appears to be randomly during it’s walk that it teleports.

They never change target destination mid-walk.

Which version are you using?

Still back at 4.0.11.
Will be doing more tests today, will post back if I have found the issue.

Try upgrading. Since 4.0.11 I have rewritten the navmesh clamping code in the RichPath class.