Adding Variation To Grid Path

Hi,

I’m using a Grid Graph for pathfinding hundreds/thousands of units on a map for a strategy/simulation game. The player can place roads on the grid, and the roads are the same width as one grid cell/node.

Currently all characters follow the exact same path and walk down the center of each cell, so they appear like a chain on the road. I’d like to randomize where on the road they walk, but not so much that they leave the road itself.

I looked into the Alternative Path modifier, however this seems to route them via a different cell so they leave the road, even when the destination is straight ahead.

What would be the best (and most efficient) way of achieving this?

Thanks for the help!

Still struggling to find a solution to this one.

For a bit more context, I’m now using AILerp to handle movement as it seems more reliable when Time.TimeScale is sped up. I tried the Funnel Modifier which does help reduce the identical nature of every unit’s pathing, however found that on corners around non-walkable cells it cuts too close to the corner so the unit ends up on the non-walkable cell. There doesn’t seem to be any character radius settings that can keep the units Xcm from the edge of the walkable area.

Any ideas?

Thanks very much!

Hi,

An idea but not sure if it would fit your use case…

Can you double the grid graph resolution such that roads are two nodes wide, eg have a left and right lane?

And then perhaps use the ITraversalProvider feature to introduce a slight randomised cost for road nodes?

The end result I’m imagining would be that units stick to roads but randomly move between left and right side

You could even go higher resolution for smoother variations, but with the less than ideal overall cost of the increased grid size in non road areas

I might be able to help here; I was having the same issue in my own game. I’m making a top down game, and my solution was to offset the target destination perpendicularly to the target based on how far the unit was from them. This made some very dynamic feeling pathfinding in my case, making enemies take “the long way” sometimes (which looked great in effect), or walking “towards” the player, but not “to” them.

You might also want to look into RVO/Local Avoidance as well: Local Avoidance - A* Pathfinding Project

Hi

One approach that I think could work well is to make each agent have an ITraversalProvider which adds deterministic noise to the cost of each node.

For example agent A could think that a given node has a high cost, while agent B thinks it’s pretty easy to traverse.

This could be done using e.g. perlin noise, or some other kind of noise function.

I haven’t tested this myself, but I think it could lead to some pretty nice movement.
It’s important that for a given agent, the noise stays constant, so that it doesn’t try to change its path all the time.

See Agent-Specific Pathfinding - A* Pathfinding Project