Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Pathfinding Issue, NPC refusing to walk path?

Greetings, Thanks for taking a look into my issue.

I made a pathfinding script in which I told an NPC to follow a path. (called Jake) The path gets correctly created and I made it so a line shows how the path goes. It's just that Jake refuses to follow the line and walks off on his own.

Here is the code, Any help is appriciated

path = game:GetService("PathfindingService"):FindPathAsync(game.Workspace.Pathfinding.Start.Position, game.Workspace.Pathfinding.Finish.Position)
waypoints = path:GetWaypoints()

for i = 2, #waypoints do
	local lastWaypoint = waypoints[i-1]
	local currentWaypoint = waypoints[i]
	print(currentWaypoint)
	
	local segment = Instance.new("LineHandleAdornment")
	local lastPosition = lastWaypoint.Position + Vector3.new(0, 0.5, 0) - game.Workspace.Pathfinding.Start.Position
	local currentPosition = currentWaypoint.Position + Vector3.new(0, 0.5, 0) - game.Workspace.Pathfinding.Start.Position
	local toCurrent = currentPosition - lastPosition
	local distance = toCurrent.Magnitude
	
	segment.CFrame = CFrame.new(lastPosition, currentPosition)
	segment.Parent = game.Workspace.Pathfinding.Start
	segment.Adornee = game.Workspace.Pathfinding.Start
	segment.Thickness = 10
	segment.Length = distance
	
	print(toCurrent)
	script.Parent:MoveTo(toCurrent)
	
	
	local waypointType = currentWaypoint.Action	
	if waypointType == Enum.PathWaypointAction.Jump then
		segment.Color3 = Color3.new(1, 1, 0)
	else
		segment.Color3 = Color3.new(0, 1, 0)
	end
end

3 comments

0

Why is toCurrent = currentPosition - Position? Shouldn't it be just the next waypoint?

0

Like 'thebayou' said but toCurrent should equal currentWaypoint.Position. also I would use a humanoid for the moveTo method or at least lerp the CFrame of the model to the current waypoint

0

welp, It was just that Tocurrent should have been currentwaypoint.Position

1 answer

welp, It was just that Tocurrent should have been currentwaypoint.Position

1 comment

0

Like I said but okay.

This discussion is preserved as it was. New answers, comments, and votes are closed.