#Pathfinding mob can be affected with players

1 messages · Page 1 of 1 (latest)

wise cypress
#
local start = workspace.StartPoint
local endpoint = workspace.EndPoint

local PathfindingService = game:GetService("PathfindingService")
local ServerStorage = game:GetService("ServerStorage")

local rig = ServerStorage.Rig
local spawnCD = 3
local mobSpeed = 8
local debounce = {}

local function SpawnMob()
    local unit = rig:Clone()
    unit.PrimaryPart = unit:WaitForChild("HumanoidRootPart")
    unit:SetPrimaryPartCFrame(start.CFrame)
    unit.Parent = workspace
    unit.PrimaryPart:SetNetworkOwner(nil)
    unit.Name = "Rig"

    local humanoid = unit:FindFirstChild("Humanoid")
    humanoid.WalkSpeed = mobSpeed

    local hrp = unit.PrimaryPart

    local path = PathfindingService:CreatePath({
        AgentRadius = 2,
        AgentHeight = 5,
        AgentCanJump = true,
        AgentCanClimb = true
    })

    path:ComputeAsync(hrp.Position, endpoint.Position)

    if path.Status == Enum.PathStatus.Success then
        local waypoints = path:GetWaypoints()

        for _, waypoint in pairs(waypoints) do
            if unit and unit.Parent and humanoid and humanoid.Parent then
                humanoid:MoveTo(waypoint.Position)
            else
                break
            end
        end
    end
end

endpoint.Touched:Connect(function(hit)
    local mob = hit and hit.Parent
    if mob and mob:IsA("Model") and mob.Name == "Rig" and not debounce[mob] then
        debounce[mob] = true
        mob:Destroy()
        debounce[mob] = nil
    end
end)

task.spawn(function()
    while true do
        SpawnMob()
        task.wait(spawnCD)
    end
end)

how to make it that players cant touch, push, block the mobs?

i tried to cancollide false all baseparts when clone but didnt work

half plaza
wise cypress
half plaza
#

I can't really infer much from that picture

wise cypress
#

then the path is just straight in the end

half plaza
#

Do they have any obstacles that your using the pathfinding to avoid?

wise cypress
#

no, its weird that they keep going offtrack

#

look

#

heres how they move lol

half plaza
#

I'm not sure why they are doing that, very weird. Instead of using pathfinding, could you just have them directly walk to the end portal?

wise cypress
#

they stop in the middle

#

idk which obstacle lol

#

with moveto, its very clear now but still stops

half plaza
#

And if you push them to the side with a part, they would continue on?

#

I'd try to select that point in space with studio. If the part is locked you might have to search through the workspace or use a raycast to figure out whats there

wise cypress
#

oh i seemed to find it