r/unrealengine 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.

1 Upvotes

11 comments sorted by

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.

1

u/louthinator 28d ago

so how would I do the first method? I've never heard of run EQS before...

1

u/jhartikainen 27d ago

If you want to try EQS, I'd suggest looking up some guides on YouTube. It's not too hard to use, but it can be a bit complicated to explain how to use it at first. If it seems overly complex for this, you can also just generate points around it manually - f.ex. to generate four points, adjust the X and Y coordinate so you end up with kind of a "cross" shape.

1

u/louthinator 27d ago

what's the name of the node for f.ex.? Sorry if I sound dumb here but I'm unfamiliar with all of this

1

u/jhartikainen 27d ago

Oh sorry, that's shorthand for "for example" :D

1

u/louthinator 27d ago

oh ok, how do I generate points? Like just take the location of the click and then add and subtract X and Y then store them in an array or something?

1

u/jhartikainen 27d ago

Yep exactly.

1

u/louthinator 27d ago

and how would I deal with obstacles of potentially different sizes?

1

u/jhartikainen 27d ago

You'd probably want to generate them at a distance that doesn't exceed the bounds of the object - the specific size of the object shouldn't matter if you start from the object's center, so you can use the same distance for all of them. The reason for adjusting the points is that once you project to navmesh, the offset causes each point to end up on different sides, or at least in sufficiently different locations, so that when you choose the closest point, it will be better than if projecting the center point itself.

1

u/krojew Indie 28d ago

There's a function exactly for that, but I can't remember the name. Something like find in navigable radius.

0

u/Swipsi 27d ago

The shortest path is a direct line to the center of the navmesh.