PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Preventing Overlapping Parts

Preventing Overlapping Parts

Jun 23 2018, 2:02 AM PST

Problem

You want to position a part so that if another part is occupying the same space, the part you’re positioning will move up until it no longer occupying the same space.

Solution

Use Vector3 values to position it.

local part = Instance.new('Part')
part.Parent = Workspace
part.Anchored = true
part.Position = Vector3.new(0, 0, 0)
local part2 = part:clone()
part2.Parent = Workspace
part2.Anchored = false

Discussion

We create a part like normal, parent it to the Workspace and then anchor it. We then change its position to the origin. We then create a new variable “part2” and set it to be a clone of the first part using the clone method. By default cloned objects are not parented to the Workspace. We then set Anchored on this new cloned part to false.

By settings Anchored to false, we allow the part to move out of place. If you have two parts that are overlapping and you allow it to move, then it will move up and out of the way. Otherwise, if both parts are Anchored, then they will be occupying the same space.

Tags:
  • part
  • anchor
  • script