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))
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))