I am making a game that I need the enemy to chase a player if they were attacked, but the pathfinding service is really wonky for me and I need help.
I needed for the enemy to not go "inside" of the player, but be on a range / offset so it will be more realistic.
I tried adding offset like this in every waypoint that was generated by the pathfinding service:
-- HumRoot = humanoidrootpart of the enemy that is chasing
-- Humanoid = humanoid of the enemy that is chasing
-- destination = position of the player's humanoidrootpart who attacked
local range = 5 -- studs on how much distance should the enemy be to start attacking
while not destinationReached do
path:ComputeAsync(HumRoot.Position, destination)
for _, waypoint in pairs(waypoints) do
local offset = (HumRoot.Position - waypoint.Position).Unit*range
Humanoid:MoveTo(waypoint.Position + offset)
Humanoid.MoveToFinished:Wait()
end
--removed some code about computing if destination is reached
end
the problem to this is, the enemy always look back / move back a step or two before reaching the destination, and sometimes they just stop. It commonly stops when there's an obstacle tho.
Any help is appreciated! Thank you!
