There’s a fly script I’m working on where an AlignOrientation orients a character’s HumanoidRootPart based on their camera LookVector.
local camlookat = camcframe.LookVector
alignOrientation.CFrame = CFrame.new(rootpart.CFrame.Position, rootpart.CFrame.Position + camlookat)
It works, but the problem is that it makes the front of the HumanoidRootPart face the LookVector of the Camera, while I want the top of the HumanoidRootPart to face the camera LookVector whilst the front faces the negative UpVector of the Camera.
Basically I want the player to fly head-first, face-down.
I tried rotating the LookVector on an axis using the function in this post, but the results are really wonky
If this is the case, this is pretty much the answer to your question, we can just create a new rotation matrix using these vectors.
Does this give you what you’re looking for?
local up = camera.CFrame.LookVector
local negLook = camera.CFrame.UpVector
local right = up:Cross(negLook)
alignOrientation.CFrame = CFrame.fromMatrix(
root.Position,
right,
up,
negLook -- the z vector is flipped in Roblox so the look vector is negative Z axis
)
Oh that’s interesting, could you provide your script or a repro file? It’s working as expected for me
Or here’s what my implementation looked like if you want to gloss over it:
local camera = workspace.CurrentCamera
local root = script.Parent:WaitForChild('HumanoidRootPart')
local attachment = Instance.new('Attachment', root)
local alignOrientation = Instance.new('AlignOrientation')
alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
alignOrientation.RigidityEnabled = true
alignOrientation.Attachment0 = attachment
alignOrientation.Parent = root
local alignPosition = Instance.new('AlignPosition')
alignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
alignPosition.RigidityEnabled = true
alignPosition.Attachment0 = attachment
alignPosition.Position = root.Position + Vector3.yAxis * 3
alignPosition.Parent = root
game:GetService('RunService').RenderStepped:Connect(function()
local up = camera.CFrame.LookVector
local negLook = camera.CFrame.UpVector
local right = up:Cross(negLook)
alignOrientation.CFrame = CFrame.fromMatrix(
root.Position,
right,
up,
negLook -- the z vector is flipped in Roblox so the look vector is negative Z axis
)
end)