Rig Movement Issues

Try skipping the first waypoint. Since the mob is already positioned in that waypoint.

for waypoint=2, #waypoints:GetChildren() do
	ForceMoveTo(humanoid, waypoints[waypoint].Position)
end

He is now getting stuck at the second waypoint.

Can you output the current waypoint and the distance.

for waypoint=1, #waypoints:GetChildren() do
	print(waypoint)
	ForceMoveTo(humanoid, waypoints[waypoint].Position)
end
function ForceMoveTo(humanoid : Humanoid, location : Vector3)
	local reached = false
	local rootpart = humanoid.RootPart
	local offset = getDistance(location, rootpart.Position).Unit
	while not reached do
		humanoid:MoveTo(location + offset)
		reached = humanoid.MoveToFinished:Wait()
		print(getDistance(location, rootpart.Position))
	end
	local magnitude = getDistance(rootpart.Position, location).Magnitude
	print(magnitude )
	if magnitude > 1 then
		return ForceMoveTo(humanoid, location)
	end
end

image

The list continues on, until it hits a point where the same number repeats over and over.

There’s probably a difference on the size on our rig. You can adjust the magnitude needed to recursively call the forcemoveto again. Instead of checking the magnitude by higher than 1 you can use the rig’s size. Which on the output is 3.
Try:

	if magnitude > 3 then
		return ForceMoveTo(humanoid, location)
	end

You can also simply just remove the y axis before checking the magnitude.

The rig is now reaching the second waypoint, but not getting past it. I don’t understand why.

My mistake, it should be 4 since the outputs is higher than 3.

if magnitude > 4 then
	return ForceMoveTo(humanoid, location)
end

Alternatively you can just remove the y axis.

function removeYAxis(vector : Vector3)
	return Vector3.new(vector.X, 0, vector.Z)
end

function getDistance(start : Vector3, location : Vector3)
	return (start - location)
end

function ForceMoveTo(humanoid : Humanoid, location : Vector3)
	local reached = false
	local rootpart = humanoid.RootPart
	local offset = getDistance(location, rootpart.Position).Unit
	while not reached do
		humanoid:MoveTo(location + offset)
		reached = humanoid.MoveToFinished:Wait()
	end
	local magnitude = getDistance(removeYAxis(rootpart.Position), removeYAxis(location)).Magnitude
	print(magnitude)
	if magnitude > 1 then
		return ForceMoveTo(humanoid, location)
	end
end

After changing the Magnitude, it works perfectly. Thanks for all the help.

1 Like

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