I am clamping the character’s position using the following function, however it would be nice to actually pull character towards the node (it might be heavily inclined). How do I get GraphNode’s normal?
// keeps the vector on the same y-level as the navmesh's surface, and corrects it
// if it's too far (within horizontal-plane) from the nearest position on the navMesh
protected void ClampToNavMesh(ref Vector3 wanted_nextAi_pos, int graphMask=-1, int tagMask=-1) {
NNConstraint constraint = NNConstraint.Default;
if(graphMask != -1) {
constraint.graphMask = graphMask;
}
if(tagMask != -1) {
constraint.constrainTags = true;
constraint.tags = tagMask;
}
//glue to the surface:
NNInfo info = AstarPath.active.GetNearest(wanted_nextAi_pos, constraint);
wanted_nextAi_pos.y = info.position.y;
//discard the user's vector if it's too far, even after the y-correct:
if((wanted_nextAi_pos - info.position).sqrMagnitude > 0.01f) {
wanted_nextAi_pos = info.position;
}
}