"Drawing" a line between two parts

I’m trying to create a function that creates a part that resembles a line and ‘connects’ two parts with it, but I’m completely lost.

Here’s a visual representation of what I mean:

I have code to make the line the appropriate length:

path.Size = Vector3.new((pos1 - pos2).Magnitude, 0.1, 0.1)

I’ve also got it to spawn the line part directly in between the two parts, so all that’s left is getting the correct orientation.

I’ve used different combinations of atan, asin and acos to try and figure out what the line’s orientation should be, but when I figure out what works for two objects with a certain position, it fails for any other objects with a different position. I’ve tried creating visualizations in MS paint but end up even more confused. My brain is pretty much fried from trying to figure this one out all day. How can I best calculate what the line part’s orientation should be?

1 Like

All you need to do is say

local CFrame = CFrame.new(Part1.Position, Part2.Position) 

local Rotation = CFrame - CFrame.Position

And multiply the line part’s CFrame position by the variable Rotation.

Another way would be to set the part’s CFrame so it’s in the middle of the parts, and is “looking” at one of them. Using the CFrame constructor with lookAt:

local Center = (pos1 + pos2) / 2
part.CFrame = CFrame.new(Center, pos1) -- part will be "looking" at pos1
9 Likes

You should try this-

path.Size = Vector3.new( thickness , thickness , distance )
1 Like