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

Use Lerp to an Object between Two Object

Use Lerp to an Object between Two Object

Jun 23 2018, 2:02 AM 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