MoveTo doesn't reach the center of the part and comes to other point a little bit early

NOTE: please read post fully, i saw so much replies on the similiar topics where people have same problem as me, and people who was trying to help didn’t read topics fully and though people had problem with 8 sec timeout, i DONOT have 8 seconds timeout problem, i have problem that my mobs are reaching waypoints, but a little bit early, and i want them to reach the CENTER of waypoints, not just come close to them.
There’s function that removes timeout:

function MoveNPC(Point, Character)
	--local HRP = Character.HumanoidRootPart
	--local H = Character.Humanoid
	repeat
		wait()
		if Character ~= nil then
			if Character:FindFirstChild("HumanoidRootPart") then
				if Character:FindFirstChild("Humanoid") then
					Character.Humanoid:MoveTo(Point)
				else
					break
				end
			else
				break
			end
		else
			break
		end
	until (Character:FindFirstChild("HumanoidRootPart").Position - Vector3.new(Point.X, Character:FindFirstChild("HumanoidRootPart").Position.Y, Point.Z) ).magnitude <= 1
end

Can anybody please help me make mobs reach the center of the waypoints??? It’s a little problem but it really annoys me! I think it will annoy some players too.

Your magnitude check only has a threshold of one. To make it stop when it’s closer just make the threshold lower.

Code:

function MoveNPC(Point, Character)
	local HRP = Character:FindFirstChild("HumanoidRootPart")
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
	
	if not HRP or not Humanoid then
		return
	end
	
	while (HRP.Position - Vector3.new(Point.X, HRP.Position.Y, Point.Z)).Magnitude <= 0.2 do
		Humanoid:MoveTo(Point)
		
		task.wait()
	end
end

it doesn’t work, mobs now not moving

I forgot to add a not, check my edited code.

Also i’ve already tried to making number 1 lower, and if it less than 0.7 mobs just stops at the first point and they still don’t go to center.

Why can’t you just do :MoveTo? Are the parts further than 8 seconds away?

Yeah, there are paths that takes more than 8 seconds, sadly

Still they don’t move, i think it’s beacuse “while” works only when mob is close, but mob is not. To make it move we need to check until it close, not while it close. I’ll try to change < to >
Edit: they walk, but as i said if it less than 0.7 they just stop at the first waypoint.

Could you use this? It’s just a loop but checks if the path is finished using :MoveToFinished.

Code:

function MoveNPC(Point, Character)
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
	
	if not Humanoid then
		return
	end
	
	local targetReached = false
	
	local connection
	connection = Humanoid.MoveToFinished:Connect(function()
		targetReached = true
		connection:Disconnect()
	end)
	
	repeat
		Humanoid:MoveTo(Point)
		task.wait(6)
	until targetReached
end

They don’t move (filling up to 30 symbols beacuse of minimum symbols limit)

Could you show the code where you’re calling MoveNPC?

Sure!

for d=1, #workspace.Canyon.Waypoints:GetChildren() do					 
    MoveNPC(workspace.Canyon.Waypoints:FindFirstChild(d).Position, mob)					
end

Edit: your script worked, mobs just started moving after 6 seconds, but mobs moves at the next waypoint only after 6 seconds, i just used task.wait() and it still ends a little bit early. And also it causing a little lag

I made better optimized MoveNPC function, beacuse so much zombies were making a lag. Why? Simple, game was running :MoveTo() so much, and that was making a lag. Now it runs it only when MoveToFinished, and checks if zombie is got to the end, if not - he go to the point again.

But… I still have that problem, and games like tower defense simulator and others doesn’t have that problem.

Tower.Humanoid:MoveTo(v.Position+Vector3.new(math.sqrt(Tower.PrimaryPart.Size.X/2),0,math.sqrt(Tower.PrimaryPart.Size.Z/2))*CFrame.lookAt(Tower.PrimaryPart.Position,v.Position).LookVector)

thats from my code. v is the destination and tower is the character. you just need to change your variables then it should work.

Thanks for answering! I already found a way, humanoids causing a big lag so i used tween and it doesn’t have that problem, but i’ll try that way with humanoids (so if i will need to use humanoids i will know how to fix that problem), and if it will help - i will make you know!

1 Like

By the way, this module may be helpful if you want smoother turns:

I already using bezier curve to achieve that effect, but that looks better tho! Thanks for replying, i’ll try that method to make better and easier turns. (for now i using 3 parts on every turn and do bezier curve on them)