Hi there, i have tried to reach some result like that and this is what i came up with:
First you need the position of each of the two parts with their lookvector*some offset added to them
then you need the distance between those 2 vectors
after that you can define the 3rd part position as the position of a new cframe made up by the first position and the second position multiplied by the distance divided by 2
local firstpos=p1.CFrame.p+p1.CFrame.LookVector*5
local secpos=p2.CFrame.p+p2.CFrame.LookVector*5
local dist=(firstpos-secpos).magnitude
p3.Position=(CFrame.new(firstpos, secpos)*CFrame.new(0,0,-dist/2)).p
i made up this code that you can run on studio,try changing the blue or red part’s orientation or position (the hinges show where they’re looking at)
local p1=Instance.new("Part",workspace)
local p2=Instance.new("Part",workspace)
local p3=Instance.new("Part",workspace)
p1.Size=Vector3.new(1,1,1)
p2.Size=Vector3.new(1,1,1)
p3.Size=Vector3.new(1,1,1)
p1.Color=Color3.new(1,0,0)
p2.Color=Color3.new(0,1,0)
p3.Color=Color3.new(0,0,1)
p1.Position=Vector3.new(3,2,0)
p2.Position=Vector3.new(-3,2,0)
p2.Anchored=true
p1.Anchored=true
p3.Anchored=true
p1.FrontSurface=Enum.SurfaceType.Hinge
p2.FrontSurface=Enum.SurfaceType.Hinge
local b1=Instance.new("Beam",p1)
local b2=Instance.new("Beam",p2)
local b3=Instance.new("Beam",p1)
local at=Instance.new("Attachment",p1)
local at2=Instance.new("Attachment",p2)
local at3=Instance.new("Attachment",p3)
b1.Attachment0=at
b1.Attachment1=at3
b2.Attachment0=at2
b2.Attachment1=at3
b3.Attachment0=at2
b3.Attachment1=at
game:GetService("RunService").RenderStepped:Connect(function()
local firstpos=p1.CFrame.p+p1.CFrame.LookVector*5
local secpos=p2.CFrame.p+p2.CFrame.LookVector*5
local dist=(firstpos-secpos).magnitude
p3.Position=(CFrame.new(firstpos, secpos)*CFrame.new(0,0,-dist/2)).p
end)
edit:changed script for workspace