How would I get the point that two parts are facing?

Hello,

I would like to know how to get the point that two parts face, as demonstrated by the diagram below. (Excuse the lack of beauty!)
bitmap
I am not really looking for a mathematical solution; rather, I would like to know how I could get a part positioned there quickly and easily. A plugin would be ideal, but if you have any other solution, I would be glad to hear it.

3 Likes

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

2 Likes

PLUGIN:

Use OuterTouch and click the desired faces of the Parts you want to connect.

2 Likes

Thanks for your response.

Unfortunately, this does not seem to be what I am looking for. With your solution, the third part does not always appear where the two other LookVectors should intersect.


Notice how the beams here are not parallel with the hinges.

2 Likes

HalfTouch is actually the one I’m looking for.

I have the original plugin, but it doesn’t have that feature, which made me stuck. With HalfTouch, I can do a bit of scaling to find the intersection point. Thank you.

1 Like