I was testing pathfinding. the MoveTo() meathod works on the normal r15 rigs but once i tried on custom rig it didnt work. I changed everything in the code accordingly and there are no errors. The model is not achored either. Any tips on fixes?
Make sure you rigged it correctly
How do I check that? I didnt rig it myself.
bump, how to i make sure its rigged correctly
Btw you spelled method wrong, Did you check that all of the parts are un-anchored? If you generated the NPC with the animation rig builder plugin the HumanoidRootPart is anchored by default?
Can you show us the error or reproduction?
It says move which in the code means the thing is running. (the part is for detection of player, i unachored and is massless). this all worked on a dummy nromal r15
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath({
AgentRadius = 3,
AgentHeight = 6,
AgentCanJump = false,
})
local char = script.Parent
local humanoid = char.Humanoid
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
local function followPath(destination)
local success, errorMessage = pcall(function()
path:ComputeAsync(char.RootPart.Position, destination)
end)
if success and path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
if blockedWaypointIndex >= nextWaypointIndex then
blockedConnection:Disconnect()
followPath(destination)
end
end)
if not reachedConnection then
reachedConnection = humanoid.MoveToFinished:Connect(function(reached)
if reached and nextWaypointIndex < #waypoints then
nextWaypointIndex += 1
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
nextWaypointIndex = 2
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
warn("Path not computed!", errorMessage)
end
end
local searching = false
local foundPlayer = nil
local debounce = false
char.RootPart.EyeSight.Touched:Connect(function(part)
if debounce == false and searching == false then
debounce = true
if part:FindFirstAncestorOfClass("Model") then
local player = part:FindFirstAncestorOfClass("Model")
if player:FindFirstChild("Humanoid") then
print("found person")
foundPlayer = player
searching = true
end
end
task.wait(0.2)
debounce = false
end
end)
while task.wait(0.02) do
while searching == true do
if (char.RootPart.Position - foundPlayer.HumanoidRootPart.Position).Magnitude < 10 then
print("player died")
foundPlayer = nil
searching = false
break
end
if (char.RootPart.Position - foundPlayer.HumanoidRootPart.Position).Magnitude < 52 then
followPath(foundPlayer.HumanoidRootPart.Position)
print("move")
else
searching = false
foundPlayer = nil
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
task.wait(0.01)
end
end
bump, still unsolved xd, taking any tips at this point