I’m currently working on a tower defense game. I’m trying to get the mobs to follow the path.
I’ve tried using the Pathfinding service and making my own waypoints and making it move between them but the mob does weird things. When using PathFinding, it skips all of the waypoints and goes for the last one and switches midway. When I use:
local Mob = script.Parent
local humanoid = Mob:WaitForChild("Humanoid")
local waypoints = game.Workspace.Waypoints
for waypoint=1, #waypoints:GetChildren() do
humanoid:MoveTo(waypoints[waypoint].Position)
humanoid.MoveToFinished:Wait()
end
Mob:Destroy()
The mob goes to all of the waypoints but doesn’t stop at the waypoint and goes further before turning (video).
robloxapp-20241214-1035008.wmv (1.3 MB)
Pathfinding:
local Mob = script.Parent
local humanoid = Mob:WaitForChild("Humanoid")
local waypoints = game.Workspace.Waypoints:GetChildren()
local path = game:GetService("PathfindingService"):CreatePath()
local success, errorMessage = pcall(function()
path:ComputeAsync(humanoid.RootPart.Position, waypoints[2].Position)
end)
if success and path.Status == Enum.PathStatus.Success then
for i=2, #waypoints do
local destination = waypoints[i].Position
local success, errorMessage = pcall(function()
path:ComputeAsync(humanoid.RootPart.Position, destination)
end)
if success and path.Status == Enum.PathStatus.Success then
humanoid:MoveTo(path:GetWaypoints()[i].Position)
humanoid.MoveToFinished:Wait()
print("Moving")
else
warn("Path not computed!", errorMessage)
end
end
else
warn("Path not computed!", errorMessage)
end
robloxapp-20241214-1043537.wmv (755.0 KB)
Sorry for the bad video quality and I checked the dev forum and just couldn’t find something for this.