Big moving object. (Train)


#1

I have got big moving object in my scene, to be more precise it is a train with wagons. I’m using recast graphs.
Do you have any suggestions how to do pathfinding in this situation.

Pathfinding for other units not for a train naturally.


#2

Hi

Depends on your game mechanics. But at least initially I would go with a rectangular navmesh cut for the train and it’s wagons. Preferably with quite a bit of margin.

See https://arongranberg.com/astar/docs/navmeshcutting.php


#3

But is it possible to recreate navmesh after cutting or will it leave a trail of chopped navmesh after my moving train ?


#4

Hi

The navmesh cut component works perfectly well with moving obstacles. Take a look at the video on that page I linked. Internally it saves the original navmesh and re-cuts it every time an obstacle moves.


#5

Yes I just saw it, I will try it. Thank you.


#6

Works almost like a charm :).

I got two issues with it. And one small suggestion.

First you cannot specify what graphs are going to be cut, you have to cut all of them.

Second after cutting there is a space between wagons that is smaller than a radius of a characters but pathfinding is still guiding throught this little space.

My suggestion would be to add additional condition for cutting, not only distance but also time. When the body have not crossed the distance for a specified time it could make a cut anyway. This would enchence precision when the body stops close to the distance condition. Naturally cuts only once when no changes to body position.


#7

Hi

Yeah. Currently it is only possible to disable or enable navmesh cutting for a whole graph (there is a toggle in the recast/navmesh graph settings). However you cannot set which graphs a navmesh cut updates.

The navmesh is defined as the surface for which it is safe for the center of the character to be on. So your navmesh cuts should be expanded by the character radius already. Just increase their width by 2x the character radius. I am considering adding a checkbox for automatically expanding the navmesh cut based on the field in the recast graph settings though.