i’ve created a script that uses PathfindingService. big deal. however, i’ve run into a glaring issue. whenever (and i mean, without fail!) i try telling an npc to move along a path that is generated by the PathfindingService, it always tries to ram itself headfirst into the nearest wall.
i’ve been stuck trying to figure this out for the past 2 hours. any help would be appreciated.
here is my script (whipped together to re-create the issue):
i’ve also tried raycasting, but that wasn’t very helpful.
local pathfinding_service = game:GetService("PathfindingService")
local vis_mod = require(script.waypoint_visualizer)
local npc = script.Parent
local root = npc.HumanoidRootPart
local personoid = npc.Humanoid
local goal = workspace.End
local path = pathfinding_service:CreatePath({AgentRadius = 3.5; WaypointSpacing = math.huge})
while task.wait(0.5) do
path:ComputeAsync(root.Position, goal.Position)
local waypoints = path:GetWaypoints()
vis_mod:view_waypoints(waypoints)
for i, waypoint in pairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
personoid.Jump = true
else
personoid:MoveTo(waypoint.Position) -- please stop ramming yourself into walls it will not help you
end
end
end
the ModuleScript that visualizes waypoints accurately, not my code, i just renamed the variables:
local module = {}
local visuals = {}
function module:view_waypoints(wp)
for n, x in pairs(visuals) do
x:Destroy()
end
local att = Instance.new("Attachment")
local beam = Instance.new("Beam")
beam.FaceCamera = true
beam.LightInfluence = 0
beam.Color = ColorSequence.new(Color3.fromRGB(1, 255, 170))
for n, x in pairs(wp) do
local point = att:Clone()
point.Parent = workspace.Terrain
point.Position = x.Position
if n ~= 1 then
local con = beam:Clone()
con.Attachment1 = point
con.Attachment0 = visuals[n - 1]
con.Parent = point
end
visuals[n] = point
end
task.wait(0.5)
for n, x in pairs(visuals) do
x:Destroy()
end
end
return module
screenshots: