#ai takes sharp turns(and gets itself stuck)

1 messages · Page 1 of 1 (latest)

hollow field
#

script is too big to send so ill send it as a file

lethal raft
#

there is no movment smoothing

humanoid:MoveTo() creates instant direction changes, Add rotation smoothing

local function smoothMoveTo(position)
    local targetCFrame = CFrame.lookAt(figure.HumanoidRootPart.Position, position)
    figure.HumanoidRootPart.CFrame = figure.HumanoidRootPart.CFrame:Lerp(targetCFrame, 0.1)
    
    humanoid:MoveTo(position)
end

path following too rigid... instead of waiting for exact waypoint completion check distance

for index, waypoint in pairs(path:GetWaypoints()) do
    humanoid:MoveTo(waypoint.Position)
    
    repeat
        task.wait(0.1)
        local distance = (figure.HumanoidRootPart.Position - Vector3.new(waypoint.Position.X, figure.HumanoidRootPart.Position.Y, waypoint.Position.Z)).Magnitude
    until distance < 3
end

stuck detection add position tracking to detect if AI is stuck

local lastPosition = figure.HumanoidRootPart.Position
local stuckCounter = 0

-- in your movement loop
local currentPos = figure.HumanoidRootPart.Position
if (currentPos - lastPosition).Magnitude < 1 then
    stuckCounter = stuckCounter + 1
    if stuckCounter > 30 then -- stuck for 3 seconds
        humanoid.Jump = true
        stuckCounter = 0
    end
else
    stuckCounter = 0
end
lastPosition = currentPos

better pathfinding parameters

local pathParams = {
    ["AgentHeight"] = 5.5,
    ["AgentRadius"] = 3.66,
    ["AgentCanJump"] = true,
    ["Costs"] = {
        ["Water"] = 20,
        ["DangerousArea"] = math.huge
    }
}
hollow field
#

it works but the ai is now very laggy

#

except my other ai(same code) isnt lagging

#

only difference is that one is faster