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

How do you connect a part from point A to B?

Like a laser. How do you rotate the part correctly?

1 answer

We need a few observations.

  1. The distance between a and b can be calculated as (a - b).magnitude, and this is the length of a part that stretches between them.

  2. The middle is given by their average: (a + b) / 2

  3. The direction is given by pointing towards either a or b from the middle. We can take advantage of the CFrame.new(from, lookingAt).

Thus, to connect a and b with a part:

local p = Instance.new("Part", workspace)
p.Anchored = true
p.FormFactor = "Custom"
p.Size = Vector3.new( 3, 1, (a - b).magnitude )
-- 3 is how wide
-- 1 is how tall
p.CFrame = CFrame.new( (a+b)/2, b )

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