Make crowd agent move at constant speed

I’m generating a navmesh with a plane mesh and moving my player using agentGoto(), but the player model won’t decelerate quickly enough and ends up “sliding” to the destination. I’ve tried increasing the acceleration to a high number, which achieves the affect of constant speed up until the player starts to decelerate and starts “sliding” into the destination point.

Video

I’ve also tried teleporting the agent when it gets extremely close to the destination point, but that is sometimes jarring and the player will never reach the edge of the navmesh. I noticed there are getter methods for the crowd agent’s velocity, acceleration, etc., but cannot find a way to manually set these/set a deceleration constant.

I was wondering if there was an auto-braking hook or potentially other solutions to fixing this.

Here’s a playground: https://playground.babylonjs.com/#WYM1JD#1

Update: I wasn’t able to fix the deceleration, but I added some code that:

  • Ensures that the player ends on a planted foot rather than in the middle of a stride (this is done by calculating the number of steps, rounding that to the closest whole number, and modifying the animation speedRatio based on the pct difference of actual numSteps and the closest whole number)
  • Slow down the animation based on the velocity
  • Added animation blending

The deceleration still looks weird, but I guess it’s better than before

Welcome aboard!

Adding @Cedric in case he has some magic tricks for you.

The trick I use for having a constant speed is to have a really high value for acceleration. In that case, the agent reaches the max speed very quickly. And it works for deccelation as well.

2 Likes

Is there any other solution? It doesn’t seem work…

Can you elaborate a little on what you are trying to achieve and what’ve done so far?

I’m trying to achieve constant speed throughout the whole crowd’s path, but now at the end of the path crowd’s moving speed starts to slow down smoothly

it’s a limitation of recast/detour. there is no way to set decceleration value.