#how do i make the killer chase properly

1 messages · Page 1 of 1 (latest)

forest sun
#

it must follow the survivor and pathfind at the same time
however only turns when finished with the path
look at the vid closely
code

local function FindClosestSurvivorAndPathfindTo()
    local closestSurvivor = nil
    local closestSurvivorDistance = nil
    local PathFindingService = game:GetService("PathfindingService")

    for _, survivor in workspace.survivors:GetChildren() do
        if survivor:FindFirstChild("HumanoidRootPart") and survivor:FindFirstChildOfClass("Humanoid").Health ~= 0 then
            if closestSurvivor == nil then
                closestSurvivor = survivor
                closestSurvivorDistance = (script.Parent.HumanoidRootPart.Position - survivor.HumanoidRootPart.Position).Magnitude
            else
                local distance = (script.Parent.HumanoidRootPart.Position - survivor.HumanoidRootPart.Position).Magnitude
                if distance < closestSurvivorDistance then
                    closestSurvivor = survivor
                    closestSurvivorDistance = distance
                end
            end
        end
    end

    local path = PathFindingService:FindPathAsync(script.Parent.HumanoidRootPart.Position, closestSurvivor.HumanoidRootPart.Position)
    local waypoints = path:GetWaypoints()
    for i, point in waypoints do
        local ball = Instance.new("Part")
        ball.Anchored = true
        ball.Color = Color3.new(1, 1, 1)
        ball.Shape = Enum.PartType.Ball
        ball.Material = Enum.Material.Neon
        ball.Size = Vector3.new(0.5, 0.5, 0.5)
        ball.CanCollide = false
        ball.Position = point.Position
        ball.Parent = workspace
        game.Debris:AddItem(ball, 1)
        script.Parent:FindFirstChildOfClass("Humanoid"):MoveTo(point.Position)
        script.Parent:FindFirstChildOfClass("Humanoid").MoveToFinished:Wait()
    end
end

while task.wait(0.25) do
    FindClosestSurvivorAndPathfindTo()
end
clever spire
#

You need to continuously recalculate the path while the killer is moving.

forest sun
#

ok thanks ill find a way to do that

#

YES IT WORKS

frigid gale
forest sun
#

at some point in the loop i call the function again and then break the loop

#

earlier point = better turn

clever spire