I have a question about CFrames.
Im making a hover tank. The tank has pitch and roll rotations
I would like goal.LookVector
to be pitch.LookVector
, and goal.RightVector
to be roll.RightVector
How could I manipulate the CFrame to achieve this?
At the moment I am doing this:
return CFrame.fromMatrix(
mainPart.Position,
Vector3.new(),
Util.getAvgVector({pitch.YVector, roll.YVector}), -- roll and pitch based on inputs
CFrame.lookAt(mainPart.Position, workspace.Camera.CFrame.Position).ZVector -- look in the direction of the camera
)
But it doesnt have the correct result
1 Like
I should note, if the code was correct, the tank would be parallel with the wedge as it goes over it
1 Like
I solved the problem.
local function getOrientationCFrame(positions)
local frontAvg = Util.getAvgVector({positions.Front1, positions.Front2})
local backAvg = Util.getAvgVector({positions.Back1, positions.Back2})
local leftAvg = Util.getAvgVector({positions.Front1, positions.Back1})
local rightAvg = Util.getAvgVector({positions.Front2, positions.Back2})
local pitch = CFrame.lookAt(backAvg, frontAvg)
local roll = CFrame.lookAt(leftAvg, rightAvg)
local crossProduct = pitch.LookVector:Cross(roll.LookVector)
local cf = CFrame.new() * CFrame.fromEulerAnglesXYZ(-crossProduct.Z, 0, crossProduct.X)
return CFrame.fromMatrix(
mainPart.Position,
cf.XVector,
cf.YVector,
CFrame.lookAt(mainPart.Position, workspace.Camera.CFrame.Position).ZVector
)
end```