Hi,
I’m trying to implement the movement of the character with dpad controller, similar to moving from Unity by using NavmeshAgent.Move method (https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent.Move.html).
In Unity, the agent will be shifted by offset argument if there is no way out of the walkable area, or it get the first hit in the unwalkable area and slide along if this possible.
In Astar i couldn’t find anything suitable way for implement this because all methods i found using unity physics and CharacterController (which does not work specifically with navmesh), but found the LineCast method that could help with determining hit points beyond the walkable zone.
But there was a problem with this method:
You can see a built navmesh with a circle cut out. The green vertical line shows the current position of my “character”, the red lines its tracks.
And also we can see that the character enters into an obstacle, ignoring cuts (LineCast return false).
Using LineCast in movement code:
private Vector3 SimpleMove (Vector3 start, Vector3 offset)
{
Vector3 target = start + offset;
Vector3 result = target;
GraphHitInfo info;
// Check if there is a way out of the walkable area
if (_navMeshGraph.Linecast (start, target, _navMeshGraph.GetNearest (start, NNConstraint.None) .node, out info))
{
// ...
// Determine the point where will the character appear after a collision with an obstacle and slide
return newPosition;
}
return result;
}
On straight lines that are parallel to the coordinate axes, this doesn’t happen. How can i solve this problem?
(using Unity 2017.1.1p4, A* Pathfinding Project Pro 4.0.11)
Edit:
I try this code:
bool result1 = _navMeshGraph.Linecast(start, end, _navMeshGraph.GetNearest(start, NNConstraint.None).node, out info1);
bool result2 = _navMeshGraph.Linecast(info1.point, end, _navMeshGraph.GetNearest(info.point, NNConstraint.None).node, out info2);
where result1 return true (there is obstacle between start and end points), result2 return false
and i think this is wrong too.
where red line is line from start to end, and green vertical line is info1.point