Hello. I am trying to make an AI that walks around to random waypoints on the map. So far it is working great except when a player get's near it, in that case, even if the player is completely out of the way, it will freeze. I've been searching around for a while and cannot find anything.
My ideal solution would be just to make it so that it can just walk through just players but changing the collision setting's off doesn't seem to create that affect. An alternative would be for it to have enough power to push the player out of the way (If the first isn't possible easily and also path finding around dynamic obstacles would be too resource-intensive as I would be needing many of these AI's going around at once.)
So really my main question is why is it stopping when a player isn't even close to it? I've attached a video showing what I mean. https://drive.google.com/file/d/1vvNxl4AMPD0lcgLOc-eTkpwJF4NZ8WGw/view?usp=sharing
Thanks!
local pet = workspace.Pet
local humanoid = pet.Humanoid
local PathfindingService = game:GetService("PathfindingService")
local function getPath(destination)
local pathParams = {
["AgentHeight"] = 3,
["AgentRadius"] = 3,
["AgentCanJump"] = true,
["WaypointSpacing"] = 5
}
local path = PathfindingService:CreatePath(pathParams)
path:ComputeAsync(pet.Torso.Position, destination.Position)
return path
end
local function walkTo(destination)
local path = getPath(destination)
for index, waypoint in pairs(path:GetWaypoints()) do
local node = Instance.new("Part", workspace)
node.Size = Vector3.new(1,1,1)
node.Position = waypoint.Position
node.Anchored = true
node.CanCollide = false
humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
local disMag = (pet.Torso.Position - destination.Position).Magnitude
print(disMag)
if disMag < 10 then
return
end
humanoid.MoveToFinished:wait()
end
end
local function patrol()
local waypoints = workspace.waypoints:GetChildren()
local randomNum = math.random(1,#waypoints)
walkTo(waypoints[randomNum])
end
while wait() do
patrol()
end

1 comment
I think I've seen something related to this before, and I don't remember what the solution was, but it was something along the lines of preventing the object from switching to server/client whatever when getting to a player, but I know nothing about NPCs so I don't know for sure.