Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to Make Move Something With MoveTo to Close and Not Inside ?

Hey. I'm trying to do basic AI for my project. I'm using MoveTo for moving NPCs but they are going to exact point. I want them to go near (certain studs away from origin) not over. I tried minus some vector3 but it's not the way because sometimes it's passing the origin. I tried like this : script.Parent.Humanoid:MoveTo(workspace.Destination.Position-Vector3.new(-2,0,-2))

1 answer

I made something like this. Maybe some one will use it :)

function closePoint(destination,stud)
	local first = (script.Parent.HumanoidRootPart.Position-Vector3.new(destination.X-stud,0,destination.Z-stud)).magnitude
	local second = (script.Parent.HumanoidRootPart.Position-Vector3.new(destination.X-stud,0,destination.Z+stud)).magnitude
	local third = (script.Parent.HumanoidRootPart.Position-Vector3.new(destination.X+stud,0,destination.Z-stud)).magnitude
	local fourth = (script.Parent.HumanoidRootPart.Position-Vector3.new(destination.X+stud,0,destination.Z+stud)).magnitude
	local closest = math.min(first,second,third,fourth)
	if closest == first then return Vector3.new(destination.X-stud,0,destination.Z-stud) end
	if closest == second then return Vector3.new(destination.X-stud,0,destination.Z+stud) end
	if closest == third then return Vector3.new(destination.X+stud,0,destination.Z-stud) end
	if closest == fourth then return Vector3.new(destination.X+stud,0,destination.Z+stud) end
end



script.Parent.Humanoid:MoveTo(closePoint(workspace.MeshPart.Position,2))

This discussion is preserved as it was. New answers, comments, and votes are closed.