Hello! I am very new to creating a pathfinding system, although I have used Roblox’s in the past, and have no idea where to start. How would one create a custom pathfinding system where you are able to specify a “safe distance” (not sure if that is the correct terminology) from any other part, and that works in the air, because planes have wings and they are in the air, not the ground. It has to return a list of CFrame values, and when the plane needs to turn, the angles are at an angle depending on the intensity of the turn.
For example, say there is an object in the way of a straight path from A to B, the plane needs to find the quickest path around the object, and then continue on course.
I have no idea if I’ve explained any of this right, or if this is even possible (although I’ve done a bit of research, I just don’t know how to get started with this), so please don’t scream at me if I said something wrong
You can still use Roblox’s voxel pathfinding system, but you need to consider that your problem is not a one-step issue.
I see two steps here. I believe you first need to find a safe voxel path using Roblox’s internal pathfinding system, then you need to interpolate the plane’s movement between each voxel. Basically, smooth out the path between each safe point to travel to.
If your plan is turning sharply to the next safe pathfound voxel, then you should also determine how intense the turn is (consider the distance and the angle between each vector) to determine how much the plane should bank or pitch.
I’d start by just getting the pathfinding down first. Use Roblox’s API to generate points around objects and to and end location. Then go back through and make a second layer of functional code that checks, every time the plane moves one one point to the next, the general intensity using the factors I described above. Then you can play around with the banking and such of the plane to see what are good numbers based on those heuristics.
I was already looking at making my own, however hardcoding possible paths won’t work because this is meant to be used in lots of different games and environments, as it is a product I will be selling alongside a plane system I am making.
If you are trying to dynamically find a path for your plane, you will want to use a pathfinding algorithm. A* pathfinding has been my go-to, but you will most likely want to research it yourself to see what takes up less memory, uses less processing power, etc. I remember a post mentioning a game that had an example of a couple pathfinding algorithms, though not all of them are optimal:
If you’re looking for an implementation of a pathfinding algorithm in 3D space, it should be simple enough just to extend your node array by an extra dimension.
Using your advice, I was able to create a functioning pathfinding algorithm (admittedly taking lots of inspiration from other scripts, but the thing I’m curious about now is, how can I rotate the angle of each node depending on the intensity of the turn?
As inspiration from the video you used an example from, you can create a sort of “rope” from the plane to the current node on the path, which should give the plane enough flexibility to make smooth turns.
You can basically make a proxy part that follows the node path linearly while using some sort of constraint to keep the plane a certain distance away from the part, like a weak AlignPosition or a SpringConstraint.
It’s important to note that with this method, it would be very hard to make sure the plane does not collide with any parts because sharp curves around obstacles will cause the plane to clip it. This could probably be circumvented by drawing a ray two or three nodes ahead of the current node and seeing if it hits a part. If this happens, you can mark the node you checked as closed and redraw the path.
Another method would probably be to create a part at the node being checked and mark it as closed if it detects anything in the table returned from Part:GetTouchingParts(), redrawing the path afterwards.
I would probably use a BodyPosition whose Position property lerps to the proxy part’s position by a constant alpha every frame.
If this is too jittery, you can instead use a BodyVelocity whose Velocity property lerps to the distance between the plane’s current position and the proxy part’s position multiplied by a constant, all lerped by a constant alpha, every frame.
Both of these methods (should) exhibit the same behavior, and it would probably be a good idea to start the path with the proxy part already a couple nodes ahead to make sure your plane moves at a proper speed.
Okay, but how could I create the natural plane movement, where it rotates while turning, etc. Also, let’s say the plane is facing one direction and the player enables the autopilot, and the path goes behind where the plane is facing, how could I get the plane to do a 180* turn without it being unrealistic?
It would be great to know how you made pathfinding compatible for 3D space (i.e. Air). I am currently trying to make pathfinding for a 3D space and would greatly appreciate some help.
You can try A* pathfinding, which uses reward values to know what path is the best. Here is a turorial I saw when I wanted to make a bomberman AI with it: A* pathfinding.
Instead of a grid, you will probably want to make checkpoints around walls and corners of your map, so instead of iterating a huge 3d grid you just check those spots. I just dont know how to make the corners smoothly, but i think its possible and not necessarily part of the pathfinding system.