# Problem when i get node in nexposition

Hello Aron, I am having a problem with the route, I have set in seeker that it cannot walk through tag 1 but when calculating a route, when I ask for the node that is on the nextposition position, it sometimes returns a node with tag 1 (it is always usually when it reaches the end of its route) which should not be found on my route.
The node I am getting in the following way:
nextPosition = CalculateNextPosition (exit address, isStopped? 0f: Time.deltaTime);
GraphNode vGraphNode = AstarPath.active.GetNearest (nextPosition) .node;

I am using Raycastmodifier and SimpleSmoothModifier and the latest beta version 4.3.47.

Hi

What is CalculateNextPosition?

It is very possible that your path stops exactly on the border between two nodes. If you give the GetNearest method a point right on the border between two nodes, it’s not specified which one it will return.

CalculateNextPosition is the AiLerp procedure to move the agent:

protected virtual Vector3 CalculateNextPosition(out Vector3 direction, float deltaTime)
{
if (!interpolator.valid)
{
direction = Vector3.zero;
return simulatedPosition;
}

interpolator.distance += deltaTime * maxSpeed;

if (interpolator.remainingDistance < 0.0001f && !reachedEndOfPath)
{
reachedEndOfPath = true;
OnTargetReached();
}

direction = interpolator.tangent;
pathSwitchInterpolationTime += deltaTime;
var alpha = switchPathInterpolationSpeed * pathSwitchInterpolationTime;
if (interpolatePathSwitches && alpha < 1f)
{
// Find the approximate position we would be at if we
// would have continued to follow the previous path
Vector3 positionAlongPreviousPath = previousMovementOrigin + Vector3.ClampMagnitude(previousMovementDirection, maxSpeed * pathSwitchInterpolationTime);

// Interpolate between the position on the current path and the position
// we would have had if we would have continued along the previous path.
return Vector3.Lerp(positionAlongPreviousPath, interpolator.position, alpha);
}
else
{
return interpolator.position;
}
}

Ok. I’m going to guess that this happens when the agent ends up right at the border between two nodes. Does this match what you are seeing?

My intention is to obtain the node of the next position that the agent is going to occupy, but when I receive this node I sometimes receive a node with tag no walkable , is it not supposed that the calculated route should never step on any node with tag no walkable?

you can try it yourself and you will see how you get a node with a non-passable tag when you try to go to a destination with a non-passable area.

hi aron, have you been able to check this problem?

Hi

Have you checked what I asked?

With this graph configuration:

• width = 640
-depth = 640
• NodeSize = 0.25

I get the following positions and indices of nodes with the following positions:
Ex 1:
GraphNode vNode = AstarPath.active.GetNearest (new Vector3 (140.4, 7.3, 149.5)). Node
vNode.position = (140375, 7253, 149625)
vNode.NodeIndex = 383282

Ex 2:
GraphNode vNode = AstarPath.active.GetNearest (new Vector3 (140.5, 7.3, 149.5)). Node
vNode.position = (140375, 7253, 149625)
vNode.NodeIndex = 383282

Ex 3:
GraphNode vNode = AstarPath.active.GetNearest (new Vector3 (139.6, 7.3, 149.5)). Node
vNode.position = (139625, 7253, 149625)
vNode.NodeIndex = 383279

Ex 4:
GraphNode vNode = AstarPath.active.GetNearest (new Vector3 (139.5, 7.3, 150.5)). Node
vNode.position = (139625, 7253, 150375)
vNode.NodeIndex = 385199

I do not know if this information helps you to know if the position is between two nodes, if it does not serve you confirm it and tell me how I can check it in a more correct way, thank you.

I’d just use Debug.DrawLine to draw the problematic positions in the scene view. And then take a screenshot of that with the graph visible.

Hi Aron, here I am attaching a video of the problem:

As you can see, it is trying to walk through a node with a tag marked in the seeker as not passable.

Hi

What is your Seeker → Start End Modifier → End Point Snapping set to?
That path is definitely going into a region it shouldn’t. And I thought 3.4.47 would have fixed that.

However, note that the SimpleSmoothModifier does not take the graph into account at all. So after it has smoothed the path it may, if you use a lot of smoothing, cross over unwalkable nodes. This is the issue in your video sometimes, but not always (in particular, this is the issue when you tell it to move around a corner).

Ok my problem is the following, instead of unmarking a tag as passable so that it cannot navigate in that tag, I leave it enabled but adding a 40,000 penalty, this way it will look for another alternative route as long as it is not a very path expensive, so when you don’t find an alternative path (you walk on a path with nodes that have a 400000 penalty) I want you to always walk checking if your next position is in a node with a 40000 penalty, if it is your next position it is on a node with a 40,000 penalty I want it to stop walking, this way you always get as close as possible to a destination blocked by this tag.

So since it says that the simplifier goes through corners with penalties and not passable tag, to ignore these nodes so that my agent doesn’t stop, instead of asking if my next position is on a node with the following penalty, I should ask if my next node on the path has a penalty of 40,000 right?

To obtain the next node of the route I do it in the following way:

public GraphNode NextNode ()
{
if (this.path! = null && this.path.path! = null && this.path.path.Count> 0)
{
if (this.path.path.Count> interpolator.segmentIndex + 1)
return this.path.path [interpolator.segmentIndex + 1];
else if (this.path.path.Count == interpolator.segmentIndex + 1)
return this.path.path [interpolator.segmentIndex];
the rest
return null;
}
else
return null;
}

am I doing it the right way? Can I get my next node in a cleaner way?