GetNeareast will pass through the locked grid

When I use the GetNearest method to find a position that can be moved, if two grids are connected locked, it will still pass through the intersection of the two grids.

I am using a joystick to operate the unit.



How should I use it to avoid this problem?


Could you explain again? How do you use GetNearest to move the agent? Are you using any pathfinding at all?
Are you using tags to block the movement?

Hello, I didn’t use pathfinding, use the joystick operation unit to move directly, yes, I used the TAG to mark the locked grid.

_constraint = NNConstraint.Default;
_constraint.distanceXZ = true;
_constraint.constrainTags = true;
_constraint.tags = (int) WorldTag.Building;

and use

Vector2d clampedPos = ( nextPos, _constraint ).position;

Because the position returned by the GetNearest method is not the same as the distance from the unit position, I have length-scaled the returned position to ensure that the speed does not change when the obstacle is reached. So I feel the reason here, let the unit enter the locked area.


Well, just calling GetNearest will not do anything to validate that an agent could actually move between those two points.
I would recommend that you use the Linecast method instead.

Do I need to add Collider obstacles to use this method? Or just set the Tag of the grid and pass it directly to the start and end points.

I found that use Linecast can only on walkabke=false, So how does it work on the grid that uses Tag?

The second is how to use the method to move the unit on the edge of the obstacle. If the unit reaches the obstacle, I only find the GraphHitInfo.point. If the speed is 5, the distance from the start point to the hitPoint is 2, and the remaining 3, how? It can be moved according to the direction of the movement to continue the remaining distance on the edge 3


There is currently unfortunately no variant of Linecast that filters on a tag. You can get sort of the same information by using the overload that outputs all traversed nodes to the trace variable. (see, and then check if any of those nodes contain that tag. Is there any reason you use tags and not walkability for this?

Yes, there are 2 sides players, one can through the grid, and other side can’t, so I use the Tag