Humanoid:MoveTo() will never move to exact positions

To put it simply, I have been experimenting with humanoid:MoveTo() and I’m wondering if there’s a way to move it to exact positions.

I would like to do this without snapping the rig to the position once it is close enough.

In my testing, the rig usually stops at just under 1 stud away.

I have attempted to constantly make the humanoid walk to the intended position again if it isn’t close enough the first time, however that didn’t work.

This is a simple matter, but I couldn’t find any working methods online that didn’t include snapping the rig to the intended position.

Any help is appreciated. Many Thanks.

1 Like

You can manually control the Humanoid’s walk direction with Humanoid:Move().

What is your use case?

Positions are floats, so there will always be imprecision (i.e. you can’t use == between floats and expect consistent results).

As far as differences in the 1 stud range, you should be able to use Humanoid:Move to correct them, or you could tween the character with an AlignPosition only when the humanoid stops moving for even more exact positioning (basically snapping that doesn’t always look like snapping).

3 Likes

So, the documentation actually has multiple different functions that are used to simulate movement of models.

Here is the link.

This is a very unhelpful answer from you, he’s talking about moving humanoids or making humanoids walk, have you even read the title?

I read that it won’t move to exact positions. The answer I provided was attempting to bring attention to the PivotTo() function, which I use the most when moving humanoids. Did I misinterpret the question?

If this is about making the humanoids walk, I believe you are able to use pathfinding and play an animation simultaneously.

I’ve actually learned over time that pathfinding needs small increments to move toward. I decided to add more parts closer together which ended up fixing the problem.

Moral of the story: I added more positions (parts) for the humanoid to move to in between the initial and final during pathfinding. I assume it will work here too.

Alright, so I found a semi-decent fix to this. It works by first using :MoveTo(), then doing it again based off the distance between the rig and the target. The code goes like this:

local function walk()
		humanoid:MoveTo(target) -- get close to target first
		humanoid.MoveToFinished:Wait()

		local hrppos = hrp.Position * Vector3.new(1, 0, 1)
		local targetpos = target * Vector3.new(1,0,1)
		local dist = (hrppos - targetpos).Magnitude -- get the distance
		
		humanoid:MoveTo(target + hrp.CFrame.LookVector * dist) -- move further towards the target
		humanoid.MoveToFinished:Wait()
	end

Now, as for accuracy, I ran this 50 times, and got an average of 0.09972953796386719 studs distance between the HumanoidRootPart and the target (eliminating the Y axis from the calculations). While this is far from perfect, it is much better than the 1 stud difference before.

If anyone finds a way to further increase the accuracy that would be great. Thanks for the help.

1 Like

I guess if you really wanted to you could do a while loop.

while hrppos ~ = targetpos do
walk()
end

The only issue with this, which I found while trying different solutions to the issue, is that Humanoid:MoveTo() will go an inconsistent, fairly large (usually less then .2 studs) distance per frame (the frame being Runservice.Heartbeat), meaning that it would skip over its target and try to move backwards, and do this repeatedly, essentially walking back and forth on the target.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.