How do I give orientation data using CFrame.new?

Hello gamers, I’m trying to give a position and an orientation to the camera via CFrame, however I don’t know how to give orientation and surprisingly searching online yields results that are unrelated or straight up don’t work.
Here’s what I have right now.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(336.962, -40.25, 4.442)
1 Like

You generally use CFrame.Angles to apply rotation to a CFrame., but you can use CFrame.fromOrientation to apply values from orientation.

1 Like

Here is an example of how to:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

Camera.CameraType = Enum.CameraType.Scriptable

-- Define position and orientation vectors
local position = Vector3.new(336.962, -40.25, 4.442)
local rightVector = Vector3.new(1, 0, 0) -- X-axis
local upVector = Vector3.new(0, 1, 0) -- Y-axis
local lookVector = Vector3.new(0, 0, 1) -- Z-axis

-- Set Camera CFrame
Camera.CFrame = CFrame.new(position, position + lookVector, upVector)

1 Like

You can multiply a CFrame with position with a CFrame with rotation to combine their properties.

1 Like

How would I do this? Everything I try just changes the position to the orientation numbers.

1 Like
Camera.CFrame = CFrame.new(posX, posY, posZ) * CFrame.fromOrientation(336.962, -40.25, 4.442)

This isn’t working, I don’t know what the problem is

1 Like

Thanks for telling me that, can you send the code so I can help fix the issue :+1: :wink:

1 Like

This is the entire script. Nothing else interacts with the camera at all.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(336.962, -40.25, 4.442) * CFrame.fromOrientation(-20, -60, 0)

i’m try to get a position of 336.962, -39.25, 4.442 and an orientation of -20, -60, 0. For some reason everything I try results in only one or neither.

In the code I sent posX, posY, posZ are supposed to be the position and the numbers I typed in are the orientation.

I’ve confirmed that 336.962, -40.25, 4.442 is the correct position.

What’s happening then? I thought 336.962, -40.25, 4.442 were the orientation.

I honestly don’t know. I copied the script to a new place and everything seems to work just fine there.

CFrame.new(336.962,-40.25,4.442)*CFrame.fromOrientation(math.rad(-20),math.rad(-60),math.rad(0))

Is this work? i already check my self there no something problem

1 Like

To add a rotation factor to a CFrame, multiply it by CFrame.Angles(), which is just a CFrame with no translation but the rotation provided.

Camera.CFrame = CFrame.new(x, y, z) * CFrame.Angles(math.deg(38), math.deg(92), math.deg(31))

This reminds me on the CFrame docs it says fromOrientation uses radians but orientation uses degrees

1 Like

Also it still work if fromEulerAnglesYXZ similiar Angles
without math.rad it’s still mess up

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