How to find the closest point on a part, to a another part?

I am trying to develop some custom A* Pathfinding with a sorta navigation mesh? I’ve got the path finding, thats fine. But i want to make the NPC’s walking smoother by locating (through raycasting probably). Heres some pictures:

Red path is simple A* where the NPC simply walks to the center of the brick.
Green path is what it would look like, if i could figure out how to raycast at the connecting side between the 2 regions to find the closest angle to walk. Another pic for example:

Side note: Idk if this how actual pathfinding works on big games, I am sorta just making it up. If theres a better way to smoothen out his walking cycle feel free to help.

1 Like

You could compare the distance from the player to each of the corners of the part and then go to the center, but I’m not sure what it would look like. Not sure though, let me know what you end up trying!

You can use bezier curves to smooth out the path, but I’d recomment refactoring this system so that it doesn’t rely on center position of parts.

Sorry for bumping…

You can use a grid of nodes (array of Vector3s), as shown below:

The purple dots are the nodes, and the green dots are additional nodes for the NPC’s current position and target position.

The only two downsides with this solution I can think of is that you would have to manually place every single node and it would also have sort of a “grid” movement (unless you create a lot of nodes). One way to make the placing of nodes faster is to make a folder of parts for each node then make a script that inserts each parts’ position into an array.

You can also combine this with bezier curves to smooth out the path more like what @SubtotalAnt8185 said.