Advertisement

Colliding against objects that don’t move

Started by October 18, 2023 03:04 PM
2 comments, last by Calin 1 year, 1 month ago

A senior programmer on a forum suggested I should collide units only against objects (units) that move. The problem with that is that if unit B stops on tile TL and an unit A had already chosen a path that passes through TL by that time, A will go through B. Same thing happens if you build a building after a unit has chosen a path through the area where the construction is to take place, the unit will pass through the middle of the construction site when it reaches the spot.

The solution is to run the unit A pathfinding algorithm once again when unit B stops but that seems like a lot of work.

My project`s facebook page is “DreamLand Page”

How and when to check for impediments to a path is an optimization problem. What you describe can be a bad scenario.

Consider a bottleneck where only one unit could fit between barriers, if many things are moving through the bottleneck and you're checking too often, the pathfinder will reroute while considering the bottleneck blocked. It can also be an issue if objects are slowly navigating their way through with retry attempts, so the bottleneck is congested but still passable. When these are done well, units can take turns much like a traffic light, good systems can even let batches through in either direction, a batch one way while the opposite side waits, then a batch from the opposite side while the near side waits.

If moving through tiles you'll always want to test that the space is available before moving in, but what to do if occupied will depend on the situation. If an object is moving or pending a move, you may be better off waiting for the space to become available, if it is stationary you may have a mechanic to swap tiles with it or to push it out of the way, or it may make the most sense to reroute. All will depend on the game.

The worst systems will check it often, and if any piece is moving through the bottleneck they'll reroute, even if the piece moving through the bottleneck will be long gone by the time the object would reach the bottleneck itself.

Advertisement

Thank you frob

My project`s facebook page is “DreamLand Page”

This topic is closed to new replies.

Advertisement