# Correctly Rotating Part Between 2 Points

What I’m trying to achieve is making a straight line (a Part instance) between 2 existing Parts.

The problem I’m having is how do I make it so that the created Part is always connected from, let’s say `p1` to `p2` (1st and 2nd pre-existing Part, respectively).

I tried using the half-way point with CFrame.new and using the `lookAt` arg to make it look at `p2` but this changed nothing - the part was still perpendicular to where I expected it to be. I don’t want to take the easy way out of just rotating it with CFrame.Angles since I think that isn’t the right approach - at least, it’s not how I’d like to approach it. I could be totally wrong and in this mess for that exact reason though.

My current code is here:

``````local Illustrator = {};

function Illustrator.new(p1, p2, props)
local Distance = (p1.Position - p2.Position).Magnitude;

local BoltLine = Instance.new('Part');
BoltLine.Size = Vector3.new(Distance, 0.25, 0.25);
BoltLine.CFrame = CFrame.new(p1.CFrame:lerp(p2.CFrame, 0.5).Position, p2.Position);
BoltLine.CanCollide = false;
BoltLine.Anchored = true;
BoltLine.Parent = workspace;
end;

return Illustrator;
``````

The current result is this (‘Front’ face highlighted in Orange):
https://i.gyazo.com/1780512839eef035ac57f5fce2405c8a.png

Rotate it then.

``````BoltLine.Size = Vector3.new(0.25, 0.25, Distance)
``````

(By the way, Luau doesn’t require semicolons!)

Is that my only choice? Will this solution apply to instances where the parts are instead most distant between the X-axis? Currently, the new Part wants to be sized on the Z-axis I’ve noticed. But why? Is there no solution to that specific instance?

Also the semicolons are just a preference, I know they aren’t required - thank you, though.

This solution applies to all instances.

Simply extending the part the other way creates the effect of rotating it 90 degrees. If you don’t want that, though, just actually rotate it:

``````* CFrame.fromEulerAnglesYXZ(0, math.rad(90), 0)
``````
1 Like