#Enemy AI can't catch up to me

24 messages · Page 1 of 1 (latest)

modest panther
#

Instead of pathfinding to the player, pathfind in front of the player

silent prawn
#

it does

#

function checkSight(target)
local ray = Ray.new(Head.Position, (target.Position - Head.Position).Unit *magnitude_whenClose)
local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, {enemyModel})
if hit then
if hit:IsDescendantOf(target.Parent) and math.abs(hit.Position.Y - Head.Position.Y) < 3 then
if isChasing == true then
enemyHumanoid:MoveTo(target.Position)
return true
end
end
end
return false
end

#

magnitude_whenClose is 14

modest panther
#

Thats odd

silent prawn
#

I feel bad because hitbox has to be huge

modest panther
#

It seems that its a replication issue

silent prawn
#

and setting network owner to player will stutter even more

#

(for certain npcs)

#

I have tried fixing this for so long but I can't

modest panther
#

Try playing again, and look at what the server sees.

silent prawn
#

what is it supposed to see?

maiden fox
#

Sorry for being off topic but you are seriously using bandicam?? 😭

silent prawn
#

bro I swear

maiden fox
#

You need to give the AI a predicted path that goes further away from the Character

#

This happens because a server has a delay whenever it's replicating clients.

#

That's how servers work and you should be aware of this already if you played FPS games.

silent prawn
#

Guess making very big Hitboxes can help.

silent prawn
#

welp, now the issue is solved, thanks to everyone who tried

maiden fox
#

@silent prawn Here

function checkSight(target)
    local ray = Ray.new(Head.Position, (target.Position - Head.Position).Unit * magnitude_whenClose)
    local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, {enemyModel})
    
    --// Exit function early
    if not isChasing then return false end
    if not (hit and ray) then return false end
    if not (hit:IsDescendantOf(target.Parent) and math.abs(hit.Position.Y - Head.Position.Y) < 3) then return false end

    --// Calculate target's velocity
    local targetVelocity = target.Velocity
    
    --// Predict the target's future position
    local predictionTime = 1.5 --// how far ahead to predict
    local predictedPosition = target.Position + (targetVelocity * predictionTime)
    
    --// Calculate the distance between the AI and the predicted position
    local distanceToPredicted = (predictedPosition - Head.Position).Magnitude
    
    --// If the predicted position is too far, cap the distance
    local maxPredictionDistance = 30 -- Adjust this value as needed
    if distanceToPredicted > maxPredictionDistance then
        local direction = (predictedPosition - Head.Position).Unit
        predictedPosition = Head.Position + direction * maxPredictionDistance
    end

    enemyHumanoid:MoveTo(predictedPosition)
    return true
end
fossil vesselBOT
#

studio** You are now Level 22! **studio

silent prawn
#

Already fixed it