i am trying to make an pathfinding npc but this is what i see if i put a normal sized torso it avoids walls but when i make the torso a bit bigger it seems to not avoid the wall
My code for roblox pathfinding:
local pathfindingService = game:GetService("PathfindingService") local humanoid = script.Parent.Humanoid local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso") local destination = game.Workspace.Destination.Position local path = pathfindingService:CreatePath() path:ComputeAsync(body.Position, destination) local waypoints = path:GetWaypoints() for k, waypoint in pairs(waypoints) do humanoid:MoveTo(waypoint.Position) if waypoint.Action == Enum.PathWaypointAction.Jump then humanoid:ChangeState(Enum.HumanoidStateType.Jumping) end humanoid.MoveToFinished:Wait() end
The reason your pathfinding script is not working with a bigger torso is that Roblox's pathfinding service defaults for a normal character, which is 5 studs tall, about 3 studs in width. What you need to do is to add in path parameters.
local pathfindingService = game:GetService("PathfindingService") local humanoid = script.Parent.Humanoid local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso") local destination = game.Workspace.Destination.Position local pathParams = { ["AgentHeight"] = 5, --The height of the character ["AgentRadius"] = 2, --The width of the character from end of left arm to right arm times half. ["AgentCanJump"] = true --Can the character jump? } local path = game:GetService("PathfindingService"):CreatePath(pathParams) path:ComputeAsync(body.Position, destination) local waypoints = path:GetWaypoints() for k, waypoint in pairs(waypoints) do humanoid:MoveTo(waypoint.Position) if waypoint.Action == Enum.PathWaypointAction.Jump then humanoid:ChangeState(Enum.HumanoidStateType.Jumping) end humanoid.MoveToFinished:Wait() end
In the path params, you would need to adjust the values according to the size of your character.