My AI I am creating uses pathfinding to get to an enemy for a game I am creating.
For some reason it starts walking behind it for a moment then it turns back moving towards the enemy.
I tried making it move for a specific waypoint every heartbeat instead of following a for loop which fixes it but then the AI stands still in the middle of moving for a moment.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Here is the function I am using to move the AI which gets called every heartbeat:
local goTo = function(position)
local path = pathfindingService:CreatePath()
path:ComputeAsync(script.Parent.PrimaryPart.Position, position)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for i, v in pairs(waypoints) do
if v.Action == Enum.PathWaypointAction.Jump then
script.Parent.Humanoid.Jump = true
end
script.Parent.Humanoid:MoveTo(v.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
end
else
script.Parent.Humanoid:MoveTo(position)
end
end
oh alr that makes since (is it like 1am for you guys)
and really quick although this may not be the solution; if your trying to run 2 moveto() at the same time (one for player, one for waypoint) thats also what could cause it
(and try setting the network owner in the same script)
I have placed that inside the same script, thats what i thought when i first encounted the issue, i believe that irs because 2 loops are occuring and telling it to move there when the other loop is telling it elsewhere, and yes its 1am lol
if you are running 2 MoveTo() functions at the same time, then im pretty sure thats the problem; try to run 1 MoveTo() IF a player isnt near, ELSE (if a player is near) run the MoveTo() for the player
I created a method where I do what I mentioned I did in the description but in a way without an extra feature which I did not need anymore and fixed it. Thanks for helping