PathfindingService with non-humanoid models

So I’m trying to make an NPC boat system where on command from a script, a boat moves in a path to a new position. To do this I thought PathfindingService would be a good approach but it’s making it difficult for 2 reasons, the generated path is linear and goes straight through solid blocks and I’m not sure how to make the boat always turn so it’s always facing forwards on the path. An example path I’d like it to take is in RED, whilst the path created by PathfindingService is in BLUE. Is there a way I can use PathfindingService to make the path follow the RED path whilst making it rotate, if not, what is the best way to go about this?

Try using the AgentParameters dictionary argument when you call CreatePath. This will let you add more specifications for what paths are valid. If it’s for a boat, you probably want AgentCanJump to be false, and AgentHeight and AgentRadius to match the size of the boat (they are configured for a character-sized model by default).

I think I’m doing it a weird way, because I’m not using CreatePath. This is my code:

local path = PathfindingService:ComputeRawPathAsync(game.Workspace.Boat1.Boat1Docking.Position, game.Workspace.BoatPathfinders.Penthouse1Pathfinder.Position, 5)

local points = path:GetPointCoordinates()

game.Workspace.Points:ClearAllChildren()

for w = 1, #points do
    local part = Instance.new("Part")
    part.CanCollide = false
    part.Size = Vector3.new(1,1,1)
    part.Position = points[w]
    part.Anchored = true
    part.Parent = game.Workspace.Points
end

I rigged up a quick example using the AgentParameters on CreatePath which I think show how to work this scenario pretty easily.

Code is straight out of the wiki with agent parameters adjusted. Character Pathfinding

local PathfindingService = game:GetService("PathfindingService")

local start = game.Workspace.Start
local goal = game.Workspace.Goal
 
-- Create the path object
local path = PathfindingService:CreatePath({ AgentHeight = 1, AgentRadius = 5, AgentCanJump = false })
 
-- Compute the path
path:ComputeAsync(start.Position, goal.Position)
 
-- Get the path waypoints
local waypoints = path:GetWaypoints()
 
-- Loop through waypoints
for _, waypoint in pairs(waypoints) do
	local part = Instance.new("Part")
	part.Shape = "Ball"
	part.Material = "Neon"
	part.Size = Vector3.new(0.6, 0.6, 0.6)
	part.Position = waypoint.Position
	part.Anchored = true
	part.CanCollide = false
	part.Parent = game.Workspace
end
1 Like

CoputeRawPathAsync has been deprecated, it’s been replaced by CreatePath. CreatePath returns a Path object, which can be used to calculate a path between two points and retrieve an array of waypoints related to the path.

1 Like

I’m getting this. Some balls cover the first boat and then theres a random ball at the end of the route.

This is likely because the path is starting inside of your boat. You’ll need to move the start outside of it.

Those are some nifty arrows.

Now this is happening :I

Comes from this part http://prntscr.com/qu9cig

Can you post your code so far?

local PathfindingService = game:GetService("PathfindingService")

script.Parent.MouseClick:Connect(function()
	local path = PathfindingService:CreatePath({ AgentHeight = 1, AgentRadius = 5, AgentCanJump = false })
	path:ComputeAsync(game.Workspace.Boat1.Boat1Docking.Position, game.Workspace.BoatPathfinders.Penthouse1Pathfinder.Position)
	local waypoints = path:GetWaypoints()
	
	for _, waypoint in pairs(waypoints) do
		local part = Instance.new("Part")
		part.Shape = "Ball"
		part.Material = "Neon"
		part.Size = Vector3.new(1,1,1)
		part.Position = waypoint.Position
		part.Anchored = true
		part.CanCollide = false
		part.Parent = game.Workspace.Points
	end
end)
1 Like

You want the part to be on or very near to the water if you’re going to do it like that. Can you move it down in front of the boat just above the water an made it non collidable? I think that would work a bit better.