Pedestrian AI - best approach to cutting the crossing from road

Hi,

I am new to A* Project. My goal is to have pedestrians walk on a sidewalk and occasionally walk across the road on the crossing. I am wondering on the best approach to handle crossings.

My initial setup is that I have a placeholder scene with meshes on proper layers (Road / SideWalk / Building, etc.). In A* Pathfinder, I set as ObstacleLayerMask to non-walkable (Road / Building), using a GridGraph,and this way I am able to have agents walk on sidewalks.

Now, I want to activate crossings from time to time - for that I change tags for the crossing models (which overlays the road model), similarly like it is done in the door example. BUT since the crossing model overlays the road, it being totally non-walkable, it’s settings override the setting for the crossing. I can either disable the road model in runtime to make this work, or move the crossing harsh up, so that it’s path is on a different Y level (but I want it on a 0 level).

How this should be handled properly? Should I locate the grid tiles and manually update the graph?

Bump up. I made it work with updating walkability and tags for areas marked as crossings, the problem is the agents get stuck inside the crossing when I update walkability and make area under an agent unwalkable. I suspect that if I implemented this using cost and not boolean walkability, this might have worked, if I uppded the cost, making an agent want to flee costly area. But this is still guessing if that is the best route. @aron_granberg ?

Thank you in advance

Sorry for the late reply.

I think the best approach is to always include the crossings in the pathfinding. So the agents will always think they can use them. Then you’ll have to modify the movement scripts to do something like:

ai.isStopped = !aboutToEnterADisabledCrossing && !walkingOnCrossing

Where you use raycasts or their position to determine if the path would make it start crossing the road when the light is not green. And make sure they don’t stop if they are already crossing the road, even if the pedestrian light turns red.

@aron_granberg no worries, thank you for support. So if I understood right you suggest using mere raycasts to “sweep” area ahead of the agent, and if the raycast hits a mesh for a disabled crossing, halt? FYI I solved it by changing walkability and having tags, so far it works nice, also performance has no peaks and is really nice (1000 agents, ca. 10 crossings), but your approach definitely is more performance “aware”. Thank you.

1 Like