#why is the rig just trying to go straight to me through the wall instead of following pathfinding
1 messages · Page 1 of 1 (latest)
i think sharing the code is a necessity
its called "scripting-help"
can you share the code
fair enough
playing deltarune though give me a bit
local RunServ = game:GetService("RunService")
local PathServ = game:GetService("PathfindingService")
local bonnie = script.Parent
local bonnieHumanoid = bonnie.Humanoid
local bonnieHrp = bonnie.HumanoidRootPart
bonnieHumanoid.WalkSpeed = 65
local path = nil
local waypoints = nil
local range = 300
local function CreatePlayerPath(target)
local playerPath = PathServ:CreatePath()
local targetHrp = target.Character:WaitForChild("HumanoidRootPart")
local success, errorMessage = pcall(function()
playerPath:ComputeAsync(bonnieHrp.Position, targetHrp.Position)
end)
if not success or playerPath.Status ~= Enum.PathStatus.Success then
return nil
end
return playerPath
end
local function getClosestPlayer()
local magnitudes = {}
local target = nil
for _,player in pairs(Players:GetPlayers()) do
local dist = player:DistanceFromCharacter(bonnieHrp.Position)
if dist <= range then
table.insert(magnitudes, {dist, player})
end
end
table.sort(magnitudes, function(a, b)
return a[1] < b[1]
end)
if #magnitudes > 0 then
target = magnitudes[1][2]
end
print("Target is:", target)
return target
end
while true do
local target = getClosestPlayer()
if target then
repeat task.wait() until target.Character or target.CharacterAdded:Wait()
path = CreatePlayerPath(target)
if path then
waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Position = waypoint.Position
part.Size = Vector3.new(0.5, 0.5, 0.5)
part.Color = Color3.fromRGB(84, 60, 165)
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
game.Debris:AddItem(part, 0.5)
bonnieHumanoid:MoveTo(waypoint.Position)
end
end
else
bonnieHumanoid:MoveTo(bonnieHrp.Position)
path = nil
waypoints = nil
end
RunServ.Heartbeat:Wait()
end```
@frosty bramble @pale dawn
i figured the reason was that it ran over and over again towards the rootpart of the player and it just didnt have time to follow the waypoint itself
the problem with your code is that it restarts the path every single frame
you can make bonnie wait until she actually reaches each waypoint before moving to the next one
and you can also add a small pause between each path
i tried this and it didn't work as intended since the destination is the player
how would you suggest going along with this plan?
i have never used it
i just found it in the docs
idk if it will work
i tried that already with MoveToFinished:Wait() and it just ended up a bad result
but maybe i could tinker a little bit more
because i just put it right after the MoveTo part
you must of messed up i used it and it worked for me
the script is too long to send or smt
** You are now Level 8! **
after bonnieHumanoid:MoveTo(waypoint.Position)
add bonnieHumanoid.MoveToFinished:Wait()
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Position = waypoint.Position
part.Size = Vector3.new(0.5, 0.5, 0.5)
part.Color = Color3.fromRGB(84, 60, 165)
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
game.Debris:AddItem(part, 0.5)
bonnieHumanoid:MoveTo(waypoint.Position)
bonnieHumanoid.MoveToFinished:Wait()
end
yeah i did but it didnt have the result i wanted
bonnie just moved to where i was
not where i am
yeah you see?
while true do
local target = getClosestPlayer()
if target then
repeat task.wait() until target.Character or target.CharacterAdded:Wait()
local playerHrp = target.Character:WaitForChild("HumanoidRootPart")
local lastPos = playerHrp.Position
path = CreatePlayerPath(target)
if path then
waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
if (playerHrp.Position - lastPos).Magnitude > 5 then
break
end
local part = Instance.new("Part")
part.Position = waypoint.Position
part.Size = Vector3.new(0.5, 0.5, 0.5)
part.Color = Color3.fromRGB(84, 60, 165)
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
game.Debris:AddItem(part, 0.5)
bonnieHumanoid:MoveTo(waypoint.Position)
bonnieHumanoid.MoveToFinished:Wait()
end
end
else
bonnieHumanoid:MoveTo(bonnieHrp.Position)
path = nil
waypoints = nil
end
RunServ.Heartbeat:Wait()
end
it breaks away when you move too much and re calcs the path
@timid field does that work for you
thats him calculating the path
yeah i figured
i spent some time yesterday trying to figure out how i can optimize it
but i sorta just gave up
might see what i can do later today though
you could try making ur own pathfinding
or just try smt simple
like if the player is a certain distance raycast from the rig to the player and then dont calculate the path and just walk towards the player
it wouldnt stop the problem entirely but it would help the player not see the rig pausing
also (playerHrp.Position - lastPos).Magnitude > 5
you could change the number 5 to something bigger but the bigger will number cause the rig to go to a more previous position