Hey there!
I’m making a brand new AI, and the AI right now freaks out if it jumps. What I’m trying to do is make it jump nice and perfectly while updating instantaneously. Now, as you can see from the videos below, the one where it makes it perfectly has a wait time of 15 seconds, I don’t want that. I want it to update every frame basically, so it can run after the player.
The clip where the AI FAILS, is the one where the wait time is set to each frame. Whenever it jumps, it freaks out.
If someone could help me solve this and combine the best of both worlds, that’d be amazing! Thank you.
-- More code above here
--// Updates the pathfinding
local function update(targetModel)
local success, errorMsg = pcall(function()
Path:ComputeAsync(Killer.HumanoidRootPart.Position, targetModel.HumanoidRootPart.Position)
end)
if not success then
warn("Path computation failed: ", errorMsg)
return
end
if Path.Status == Enum.PathStatus.NoPath then
NoPathMoveTo(targetModel.HumanoidRootPart.Position)
end
local Waypoints = Path:GetWaypoints()
table.remove(Waypoints, 1)
coroutine.wrap(followPath)(Waypoints)
if Settings.DebugWithPoints == true then
for _, waypoint in ipairs(Waypoints) do
local point = Instance.new('Part')
point.Anchored = true
point.Size = Vector3.new(1, 1, 1)
point.Position = waypoint.Position
point.CanCollide = false
point.Parent = Killer.DebugStorage
Debris:AddItem(point, 0.1)
end
end
end
--// Follows the pathfinding
function followPath(waypoints)
ActiveCoroutine = coroutine.running()
for _, waypoint in ipairs(waypoints) do
if ActiveCoroutine ~= coroutine.running() then
return
end
if waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid:MoveTo(waypoint.Position)
Humanoid.Jump = true
else
Humanoid:MoveTo(waypoint.Position)
end
Humanoid.MoveToFinished:Wait()
if Settings.DebugWithPoints then
Killer.DebugStorage:ClearAllChildren()
end
end
end
while true do
update(workspace.Hacker)
task.wait() -- what ever it is. 15 seconds compared to 0.01 seconds
end