I’m trying to make a pathfinding system using large agents.
The problem is the pathfinding system.
Using small agents it works fine. But as soon as i make the agent larger than normal, they either pathfind on top of ledges and get stuck, or they try and walk through walls.
Obviously, this is not desired.
I’m using the path finding script provided by roblox inside of a while loop, running every half a second, and I’ve adjusted the path params to match the agents size.
Is this ‘normal’ behaviour? Is the pathfinding system just flawd to mainly support regular sized agents?
I’ll supply code in a moment if neccessary, cause I’m in my phone, but I mean… it’s just calculating a path. What more is there to say?
I’ve spent forever trying to solve this by increasing wall size, lowering agent height. Increasing radius… it shouldnt be this ridiculous to figure out…
adjusting the wait time makes it a bit more smooth, as its not calculating a new path to follow so frequently… but it makes my boss seem ‘dumb’. He should just follow me. (and thats with an agent size of 16 (which is still glitchy), any larger and hes trying to do some pretty ridiculous things)
local PathfindingService = game:GetService("PathfindingService")
-- Variables for the boss, its humanoid, and destination
local boss = script.Parent.Parent;
local humanoid = boss:WaitForChild("Humanoid")
local myRoot = boss:WaitForChild("HumanoidRootPart")
local destination;
local bossHeight = math.ceil((0.5 * humanoid.RootPart.Size.Y) + humanoid.HipHeight);
local bossWidth = math.ceil(myRoot.Size.X * 2);
print (bossHeight, bossWidth)
local pathParams = {["AgentRadius"] = bossWidth, ["AgentHeight"] = bossHeight, ["AgentCanJump"] = true}
-- Create the path object
local path = PathfindingService:CreatePath(pathParams)
-- Variables to store waypoints table and boss's current waypoint
local waypoints
local currentWaypointIndex
local function onWaypointReached(reached)
if reached and currentWaypointIndex < #waypoints then
currentWaypointIndex = currentWaypointIndex + 1
humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
end
end
local function followPath(destinationObject)
-- Compute and check the path
path:ComputeAsync(boss.LeftFoot.Position, destinationObject.PrimaryPart.Position)
-- Empty waypoints table after each new path computation
waypoints = {}
if path.Status == Enum.PathStatus.Success then
-- Get the path waypoints and start boss walking
waypoints = path:GetWaypoints()
local f = game.Workspace:FindFirstChild("Waypoints");
if f ~= nil then f:Destroy(); end
f = Instance.new("Folder", game.Workspace);
f.Name = "Waypoints"
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace.Waypoints;
end
-- Move to first waypoint
currentWaypointIndex = 3
if #waypoints < currentWaypointIndex then
currentWaypointIndex = 1
end
humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
humanoid.MoveToFinished:Connect(onWaypointReached)
else
-- Error (path not found); stop humanoid
--humanoid:MoveTo(boss.HumanoidRootPart.Position)
humanoid.Jump = true;
followPath(destinationObject);
end
end
local function onPathBlocked(blockedWaypointIndex)
-- Check if the obstacle is further down the path
if blockedWaypointIndex > currentWaypointIndex then
-- Call function to re-compute the path
followPath(destination)
end
end
function isPlayer(target)
local players = game.Players:GetChildren();
for i, n in pairs(players)do
if n.Name == target.Name then
return n;
end
end
return nil;
end
function GetDestination()--game.Workspace:WaitForChild("Paradigm_Dinosaurs");
for i, player in pairs(workspace:GetChildren()) do
if isPlayer(player) ~= nil then
return player;
end
end
end
-- Connect 'Blocked' event to the 'onPathBlocked' function
path.Blocked:Connect(onPathBlocked)
-- Connect 'MoveToFinished' event to the 'onWaypointReached' function
while true do
boss.PrimaryPart:SetNetworkOwner(nil);
findPlayer = GetDestination()
-- if I've found a player, and I can see them
if findPlayer ~= nil then
followPath(findPlayer)
end
wait(0.5)
end