Hello everyone, I have 2 points, point A and point B. I want to make point C in the middle of these two points. I have successfully did it with the position but not the orientation. I want the part to be the same rotation as the imaginary line between these 2 points. Help appreciated.
Code:
local cf = points[1].CFrame:Lerp(points[2].CFrame, .5)
local part = Instance.new("Part", workspace)
part.Position = cf.Position
you could add local rotation = points[1].Rotation
and then do
part.Rotation = rotation
or just part.Rotation = points[1].Rotation
1 Like
You can position the part in the middle, then make it look towards either one of the points:
local middle = points[1].CFrame:lerp(points[2].CFrame .5)
part.CFrame = CFrame.lookAt(middle.Position, points[1].Position)
1 Like
Thank you for your response. That works but unfortunately I want the left & right sides of the grey part to be facing the red parts. It’s fine though as I decided to stop working on this script.
Alr, but for future reference, you can construct a matrix where the right vector is parallel to the displacement of point1 from point2:
local right = (points[1].Position - points[2].Position).Unit
local up = Vector3.new(0, 0, 1):Cross(right)
part.CFrame = CFrame.fromMatrix(middle.Position, right, up)
2 Likes
Ohh, I thought you wanted the rotation to be the same as the parts sorry.
1 Like
It’s fine, I didn’t really make it clear what I wanted to do.
You kind of did, I just read it wrong.
1 Like