AI doesn't reach destination properly

Hello there,

So story short, I was tryng to make a tds game, I just started the project. So my question is
image
The AI is not reaching the target properly. Idk why but since I started using MoveTo, I keep noticing the issue. The AI is supposed to walk on top of the path right? My AI is leaving gap between the path. Idk how to fix this.

Could you show your code? It would also be great if you recorded the issue.

If it’s not reaching its goal by a particular distance then you can simply offset the goal’s position by that distance in order for the desired goal to be reached.

According to official documentation, PathfindingService (assuming that’s what it’s using) will leave a gap, AgentRadius, between the character and the target.

If not, I would use Humanoid:Move(Vector3 unit relative) instead. If this solves the issue, tell us which one you used.

Here is the script:

local zombie = script.Parent
local path = workspace.Path

local success, message = pcall(function()
	zombie.PrimaryPart:SetNetworkOwner(nil)
end)

if not success then
	warn("AI:",message)
end

for i=1, #path:GetChildren() do
	local destination = path[i]
	zombie.Humanoid:MoveTo(destination.Position)
	zombie.Humanoid.MoveToFinished:Wait()
	wait(1)
end
print("Reached the end.")

Instead of using MoveToFinished, what does a simple while or repeat until loop do, when waiting for (zombie.HumanoidRootPart.Position - destination.Position).Magnitude > 4 to be false?

I’m guessing that path is a folder that includes parts that act as waypoints. Try this code out:

local zombie = script.Parent
local path = workspace.Path

local success, message = pcall(function()
	zombie.PrimaryPart:SetNetworkOwner(nil)
end)

if success then
	for _,v in ipairs(path:GetChildren()) do
		zombie.Humanoid:MoveTo(v.Position)
		zombie.Humanoid.MoveToFinished:Wait()
		task.wait(1)
	end
	
	print("Reached the end.")
else
	warn("AI:",message)
end

woah, it work for some reason. Thanks for helping :slight_smile: have a nice day sir

1 Like