Like a laser. How do you rotate the part correctly?
We need a few observations.
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.
The middle is given by their average: (a + b) / 2
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 )