#Broken AI for pathfinding and chasing player.
1 messages · Page 1 of 1 (latest)
this one is the chasing
and this one is the patrol
here's the script for the ai
it has many functions
not sometimes
but when the script continues running after a long time the ai and chase starts to bug out
that's what's causing it to bug out?
your running the detection logic every single frame like 60+ times per second which includes the distance calculations for all the players and fov angle calculations using math.acos i think
thats like
expensive
or
also our main loop calls patrol() or chase() continuously without proper delays, potentially creating new paths constantly
your
wtf
@autumn trout
what
your main loop calls patrol() or chase() continuously without proper delays, potentially creating new paths constantly
also
** You are now Level 1! **
congrats
so i should give it like a wait time for these functions
your calling chase() both in hearbeat detection and in the main loop btw
so what should i do?
hmm
i got to a conclusion that the functions need a wait time of eg 0.5 sec?
no wait
replace the hearbeat logic with timed loop
like
spawn(function()
while true do
-- your detection script functions
task.wait(0.2)
end)
end)
smth liket his
also fix ur main loop
spawn(function()
while true do
if not chasing then
patrol()
end
task.wait(0.1) -- add this for proper delay
end
end)
this is all i need to do then?
pathcooldown? as in a function that makes a cooldown whenever the model trouches a part of the patrol parts?
alr thx
ops
anything?
** You are now Level 2! **