Should be easy enough. You can play around with the code to your liking.
This is an example implementation. Place this inside of the character you want to move around the nodes. Make sure you have a folder in workspace with your nodes.
local pathfindingService = game:GetService("PathfindingService")
local nodesFolder = game.Workspace:WaitForChild("Nodes")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local function moveToNode(node)
local path = pathfindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
AgentJumpHeight = 5,
AgentMaxSlope = 45,
})
path:ComputeAsync(character.PrimaryPart.Position, node.Position)
local waypoints = path:GetWaypoints()
if path.Status == Enum.PathStatus.Complete then
for _, waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
else
warn("Pathfinding failed!")
end
end
local function moveToNodesSequentially()
for _, node in ipairs(nodesFolder:GetChildren()) do
if node:IsA("BasePart") then
moveToNode(node)
end
end
end
moveToNodesSequentially()
Unfortunately this falls out of my knowledge scope, but hopefully someone else has the solution. I am not super experienced in setting my own pre-defined nodes and restricting them like that.
You can implement your own version of A* pathfinding for this. There are many useful guides on how to do so online. This video is a great starting point in my opinion. The exact details on how A* should be implemented depend on the needs of your project.
To add onto what @player356377 said, to achieve the particular movement you showed in your pictures using A*, you can just set up the nodes and the edges such that each node has no diagonal neighbors. I edited your original image to show what the edges would be (in white lines)
thats the exact way i made mine before, (i did try to make node based path finding)
For example. if the NPC was in the top left, it would only be given two options:
Left or Down
but even with thys system, it would just move to random point, plus it had to reach each point then it made a decision, instead of deciding to go to another node and using the avalible nope path to go to it
What do you mean it would move to a random point? It would move diagonally or it would move to some non-node point?
Also, what do you mean it would decide after each node? That sounds like it might be a problem with how you implemented the actual traversing. I’ve never experienced an issue like that.
If it’s jumping to other nodes, then you have not set up the edges/neighbors correctly. If you’re using PathFindingService, then I can’t give much input on that since I haven’t really messed with it. I expect that you wouldn’t be able to get your desired behavior using it.
As far as I know, there’s no way tell that service that you want to use your own custom nodes. It uses some internal navmesh that it generates and I don’t know to what extent you can customize that.