Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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

1 answer

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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 )
Ad

Answer this question