So basically
I want a part to be as long as the distance between the two parts something like
Not entirely sure how to do it with script
So basically
I want a part to be as long as the distance between the two parts something like
Not entirely sure how to do it with script
You will need to make the part as wide as the space between parts and to align/position the part so that it fills that space.
The distance between two Vector3
s is (pos2 - pos1).Magnitude
.
The position between two Vector3
s (a.k.a. their average) is (pos1 + pos2) / 2
To make a CFrame that’s positioned between the two positions and is facing the second position, you do CFrame.lookAt(center, pos2)
The CFrame needs to be the center facing pos2 not pos1 facing pos2, because parts are positioned by their centers, so this places the center of the part in the middle of the gap.
Thus,
local part -- fill these in yourself
local pos1
local pos2
part.Size = Vector3.new(1, 1, (pos2 - pos1).Magnitude + 1)
part.CFrame = CFrame.lookAt((pos1 + pos2) / 2, pos2)
If you want the part to be wide, not long, you will have to set the size’s x to the distance, not the z, then rotate the part 90° by multiplying part.CFrame
by CFrame.Angles(0, math.rad(90), 0)