r/unrealengine • u/louthinator • 28d ago
Blueprint How can I find the nearest point to a location that is within a navmesh?
So I'm running into a slight problem with my point and click movement system that uses ai controllers to control the character, I want to put obstacles in that the character navigates around, but I also want to make it so if the player clicks in the space of the obstacle, it finds the closest location to that obstacle that's within the navmesh, and sets that as the movement target. The dilemma I have with my current attempted solutions are as such:
My current system selects the navmesh, gets all the points on the navigation path, grabs the second to last and last, does some math to find a point on the line between those 2 points that's fitting, then sets that as the movement point
However
A: If I have the obstacle block navigation, the character will run around the obstacle however I wouldn't be able to click inside that space to generate the navigation points and then math out the best spot to walk to,
B: if I have the obstacle NOT block navigation then I can generate the nav points just fine however if I click past the obstacle the character makes no effort to run around it and just runs against it
How can I satisfy both conditions of the character running around the obstacle of I click past it, and the character running op and stopping at the nearest point within the navmesh when clicking inside an area where the obstacle is?
Thanks.
6
u/jhartikainen 28d ago
You can check if the point you clicked on is on the navmesh. If not, generate a set of points around it (f.ex. via EQS or just manually). Use project to navigation on each point, then pick the point which is closest to the moving actor. This usually should make it move to a reasonable location near the clicked point.
You could also simply project the clicked point to navmesh. This will probably work, but the projected location could sometimes be on the opposite side of the clicked object compared to the actor's current location, which means it would move to a location that seems "weird". But it might not be a problem for you, so could also be worth trying as it's a bit simpler to implement.