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

How do I lock a certain part inside the magnitude of another part?

How do I keep a part from going outside of a certain distance from a part? I got the magnitude part down, I just don't know how to lock the part inside of the distance.

base = script.Parent


if (base.Position - p1.Position).magnitude > 10 then
   p1.Anchored = true -- ???? 
end

Keep in note the part placement is moved by the mouse's position and is updated 1/60 of a second.

1 comment

0

Do me a favour and mark it as answered if my answer solves this issue.

1 answer

✓ Accepted answer

Position it

You said that the part placement is moved by the mouse's position. You can lock the magnitude here.

local bdiff = p1.Position - base.Position
if bdiff.magnitude > 60 then
  bdiff = bdiff.unit * 60;
end;
p1.Position = base.Position + bdiff

How does it work?
If the magnitude of the distance is more than 60, the difference is locked to a magnitude of 60 by taking the vector with a magnitude of 1 and changing its magnitude to 60

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