Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent takes an unnecessary longer path when there's a direct straight path to the target #452

Open
yelouafi opened this issue Dec 11, 2024 · 5 comments

Comments

@yelouafi
Copy link
Contributor

Using the following model and the default generation params on the generator website.

scene (7).glb.zip

the agent is not taking the obvious direct path to the target.

Screen.Recording.2024-12-11.at.12.42.09.mov
@yelouafi
Copy link
Contributor Author

FI tested on the C++ demo an it has the same issue

image

Found this similar issue on recast repo From what I understand it might be a side effect of how pathfinding computes traversal costs using mid-edge points on polygons.

One suggested solution is to do a direct raycast between the start and end point, but not sure if I can use this solution and keep using Agent/Crowds at the same time; in other words I need to override the path corridor that the agent need to take

@yelouafi
Copy link
Contributor Author

For anyone encountering the same issue, I ended up with trying a direct raycast first, if success then I use agent.requestMoveVelocity otherwise I default to agent.requestMoveTarget. Downside is you have to manually stop the agent when it 'reaches' the target point. As mentionned in recast docs, raycast helps only with 2D checks, so the workaround is only for when the target point is on the same level.

I tried pathOptimizationRange (inc updateFlags) but didn't work. Likely because optimizePathVisibility only checks for the corner after next one, which is based on the already suboptimal path computed.

Another possible alternative is to use agent.corridor.setCorridor to manually override the agent path but the method is not exposed in the current build of recast-navigation-js. And we might need to do other calls to leave the agent in the correct state.

@isaac-mason
Copy link
Owner

isaac-mason commented Dec 15, 2024

Another possible alternative is to use agent.corridor.setCorridor to manually override the agent path but the method is not exposed in the current build of recast-navigation-js. And we might need to do other calls to leave the agent in the correct state.

Exposing setCorridor shouldn't be difficult - I'm happy to find some time for that if it's going to be useful!

@yelouafi
Copy link
Contributor Author

yelouafi commented Dec 16, 2024

Hi @isaac-mason thanks for your reply. Actually I don't think it's necessary, there're other cases direct raycast can't solve (eg taking the longer detour to go around a wall). I remember reading somewhere on Mikko's blog that for scenes with big open spaces tiled meshes should be preferred, since solo ones tend to create large polygons next to small ones, for which A* doesn't perform well. I'm taking a look back at tiled meshes (had some issues with them in the past)

@isaac-mason
Copy link
Owner

I remember reading somewhere on Mikko's blog that for scenes with big open spaces tiled meshes should be preferred, since solo ones tend to create large polygons next to small ones, for which A* doesn't perform well. I'm taking a look back at tiled meshes (had some issues with them in the past)

For sure, tiled navmeshes should at minimum greatly limit the severity of these issues.

Also, thanks again for submitting a fix for the tiled navmesh issues you ran into!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants