Finding y intersection with graph

Hi,

I’d need to get y intersection on the graph (using recast) to deal with smooth character placement.
I read from somewhere that one could use GetNearest for that, but it is really not a good option as it can get you into situation that you get position from your sides on “cliff edges” and such.

The following image shows the situation.
Black lines describe the navmesh as viewed from side. The green ball is our character, for which we would like to find placement straight downwards on navmesh by doing some sort of raycasting or such on the dotted line. GetNearest (and methods taking advantage of it) of course return the closest point, which is the red dot instead of the blue dot point underneath.

This kind of situation could happen in game for example when character is knocked off the cliff (therefore moved for a moment without following the exact graph, but we’d like to drop back onto it later on).

Is there some existing functionality that could be used to resolve the situation and get for example raycast directly downwards to get the y position? If not, is there some reason why no such functionality is implemented (are there some known major bottlenecks / problems in implementing such)? Just to take in account before I start to really put effort in implementing such myself.

Hi

You can set the distanceXZ flag in the NNConstraint class.

var nn = NNConstraint.Default;
nn.distanceXZ = true;
var closest = AstarPath.active.GetNearest(point, nn).position;

See https://www.arongranberg.com/astar/documentation/dev_4_1_8_94c97625/nnconstraint.html#distanceXZ

You may want to download the latest beta as I think there are some minor bugs with the XZ distance functionality in the current release (4.0.11 at the time of writing).

But of course, thanks!