Hi! I’m working on building tools similar to the classic ones (move, clone, delete) and I need a way to ‘safe move’ parts out of other intersecting parts. This behaviour if I remember correctly is available through setting Position directly, but that’s not very future proof as there has been intention of removing that feature, so I would like a Lua implementation.
My current code does not work correctly, and is approximate at best:
local function moveUpUntilFree(part) part:BreakJoints() local wasAnchored = part.Anchored part.Anchored = true while #part:GetTouchingParts() > 0 do part.CFrame = part.CFrame + Vector3.new(0, 0.1, 0) end part.Anchored = wasAnchored end
The ideal solution would:
- preserve properties like Anchored
- provide a more exact position for the part, rather than this kind of rough approximation
- work with all kinds of parts and part shapes
What would be the best way of implementing such a function?