I made bumpercar humanoid, and move it with path finding and MoveTo, the point to move to is random generated, but at some point it completley stop to move, even if the path is clear.
As you can see by the path marker the path is clear, but the car does not move
I tried with spawn and not spawn, i tries to print out diffrent vairbales, the path is Enum.PathStatus.Success
it sday true,
true – 8 – 11
true – 9 – 11
even when it does not move
I tried adde agent raidius does not seem to help
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local PathfindingService = game:GetService("PathfindingService")
local pathParems = {
AgentRadius = 7,
AgentHeight = 15,
AgentCanJump = false
}
local path = PathfindingService:CreatePath(pathParems)
-- Variables to store waypoints table and zombie's current waypoint
local waypoints
local currentWaypointIndex
local destination
local humanoidz
local function followPath(destinationVector,zombiez)
-- Compute and check the path
path = PathfindingService:FindPathAsync(zombiez.HumanoidRootPart.Position,destinationVector)
--path:ComputeAsync(zombiez.HumanoidRootPart.Position, destinationVector)
-- Empty waypoints table after each new path computation
waypoints = {}
print(path.Status)
if path.Status == Enum.PathStatus.Success then
-- Get the path waypoints and start zombie walking
waypoints = path:GetWaypoints()
for i, v in pairs(waypoints) do
local new = Instance.new("Part")
new.Position = v.Position
new.Anchored = true
new.CanCollide = false
new.Parent = game.Workspace
game:GetService("Debris"):AddItem(new, 2)
end
-- Move to first waypoint
currentWaypointIndex = 1
print(currentWaypointIndex.." / "..#waypoints)
humanoidz:MoveTo(waypoints[currentWaypointIndex].Position)
else
-- Error (path not found); stop humanoid
humanoidz:MoveTo(zombiez.HumanoidRootPart.Position)
end
end
local function onWaypointReached(reached)
print(tostring(reached).." -- " .. currentWaypointIndex .. " -- " .. #waypoints)
if reached and currentWaypointIndex < #waypoints then
currentWaypointIndex = currentWaypointIndex + 1
humanoidz:MoveTo(waypoints[currentWaypointIndex].Position)
end
end
--variable to definae ara
local x1 = script.Parent.Parent.x1.Value
local x2 = script.Parent.Parent.x2.Value
local z1 = script.Parent.Parent.z1.Value
local z2 = script.Parent.Parent.z2.Value
local function onPathBlocked(blockedWaypointIndex)
print("##Path blocket##")
print(blockedWaypointIndex)
print(currentWaypointIndex)
-- Check if the obstacle is further down the path
if blockedWaypointIndex > currentWaypointIndex then
-- Call function to re-compute the path
local xp = math.random(x1,x2)
local zp = math.random(z1,z2)
local mp = Vector3.new(xp,38.158,zp)
print(destination)
destination = mp
print(destination)
followPath(destination)
end
end
-- Connect 'Blocked' event to the 'onPathBlocked' function
path.Blocked:Connect(onPathBlocked)
--function
local function MoveCar(car)
--spawn(function()
local xp = math.random(x1,x2)
local zp = math.random(z1,z2)
local mp = Vector3.new(xp,38.158,zp)
local destination = mp
humanoidz = car.Humanoid
path = PathfindingService:CreatePath(pathParems)
humanoidz.MoveToFinished:Connect(onWaypointReached)
path.Blocked:Connect(onPathBlocked)
currentWaypointIndex = nil
followPath(destination,car)
--humanoidz:MoveTo(mp)
--end)
end
--MoveCar(script.Parent.BumperCars.BpCar)
local BumperCars = script.Parent
while true do
--spawn(function()
MoveCar(BumperCars)
--end)
wait(4)
path:Destroy()
waypoints = nil
end