I’m trying to calculate the shortest path between 2 positions, similar to this image:
However, I don’t even know where to begin.
I’ve been looking through the devforum but unfortunately I couldn’t find any similar post.
I imagine I could calculate this by using some raycasts and getting the CFrame and the size of the parts that are between the two positions. If anyone knows how to do this or has already coded something similar before, I’d be grateful if you could explain this to me.
DISCLAIMER: I’m not asking you to code for me, I just need a step by step explanation of how to do this, or what “formula” to use in order to calculate this path
Because PathfindingService calculates a path for a humanoid to walk through. I need to calculate a path regardless of the surface (humanoids can’t walk under a part)
Unfortunately, pathfinding is a very difficult and complicated problem, which primarily involves graph theory. Without prior experience, it will take you months to develop anything even remotely close to what PathfindingService can do.
humanoids can’t walk under a part
Could you elaborate on that? Do you want your path to be under the surface, and not over it?
In addition, have you tried modifying agent parameters to satisfy your needs?
I see. The reason I don’t want to use PathfindingService is because instead of waypoints I’d like to get a table that includes the position and direction of every point where it hits the edge of a part. PathfindingService also seems pretty inefficient and slow if I have to calculate this path every frame.
What I mean is that PathfindingService will only calculate a path in which a Humanoid can walk. If the surface of the part is completely flipped, it won’t be able to calculate the shortest path and will instead return a longer path or it simply won’t find one.
Sorry if I’m not very clear, English isn’t my first language and I’m struggling to explain some of these concepts.
This feels like XY problem. Could you explain what you’re trying to achieve?
The reason I don’t want to use PathfindingService is because instead of waypoints I’d like to get a table that includes the position and direction of every point where it hits the edge of a part
The point of pathfinding is to find a path which avoids obstacles with the shortest path.
PathfindingService also seems pretty inefficient and slow if I have to calculate this path every frame.
What I mean is that PathfindingService will only calculate a path in which a Humanoid can walk. If the surface of the part is completely flipped, it won’t be able to calculate the shortest path and will instead return a longer path or it simply won’t find one.
the green line would represent the shortest path, while the red line represents what PathfindingService considers the “shortest” path (jumping over the obstacles)
What I mean is that the path I’m trying to calculate isn’t for anything to walk on it. It’s for a part to move through it, it doesn’t matter what direction it goes
You’re right, PathfindingService wouldn’t work in your case, since it’s designed to find paths on the ground, while your problem requires real 3D pathfinding.
Here is a devforum topic with a similar issue:
I do suggest rethinking your problem, because implementing your own pathfinding, especially in 3D space, is extremely difficult.
But if you do decide to go with it, you can actually find a lot of resources by doing a few google searches.