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

Creating Parts Between Others

Creating Parts Between Others

Jun 14 2019, 4:48 PM PST

Problem

You want to position a part halfway between two other parts.

Solution

Use the Vector3:Lerp method with an alpha of ½.

local part = Instance.new('Part')
part.Parent = game.Workspace
part.Anchored = true
part.Position = Workspace.Part.Position:Lerp(Workspace.Part2.Position, .5)

Discussion

The Lerp function will take two vectors and an alpha (the last argument, a number between 0 and 1) and according to the alpha will create a new vector between the two other positions. So if the alpha is .5 (or one half) it will create a Vector halfway between the two other vectors (in this case “Part” and “Part2”).

Tags:
  • movement
  • vector3
  • lerp
  • script
  • coding