Orientating a Part to 4 Points

My goal is to have a part oriented so the front face, faces the front point, the back face, faces the back point, and so on.

The images below are practically what I am trying to achieve, where each arrow represents a face and the corresponding color part the position it needs to face towards.
image
image


This is what I have below but I don’t know how to incorporate the left and right direction:

local back = workspace.Back.Position
local front = workspace.Front.Position
local left = workspace.Left.Position
local right = workspace.Right.Position

local center = (back + front + left + right) / 4

local fB = (front - back).unit
local lR = (right - left).unit
local up = Vector3.new(0, 1, 0)

local rightVector = fB:Cross(up).unit
local upVector = rightVector:Cross(lR).unit

local orientationCFrame = CFrame.fromMatrix(center, rightVector, upVector, -fB)

workspace.part.CFrame = orientationCFrame

Anything will help!

If I understand correctly what you want, shouldn’t rightVector be equal to lR and upVector be a normal vector of the plane defined by the points?

local back = workspace.Back.Position
local front = workspace.Front.Position
local left = workspace.Left.Position
local right = workspace.Right.Position

local center = (back + front + left + right) / 4

local lookVector = (front - back).Unit
local rightVector = (right - left).Unit
local upVector = rightVector:Cross(lookVector).Unit

local orientationCFrame = CFrame.fromMatrix(center, rightVector, upVector, -lookVector)

workspace.part.CFrame = orientationCFrame

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.