How to add angles and position to the same CFrame

I want to do stop the camera and the camera will be behind the player when the player is in the round
but it gives me this error 12: Invalid argument #2 (Vector3 expected, got CFrame)

local repStorage = game:GetService("ReplicatedStorage")

local runService = game:GetService("RunService")

local Inround = repStorage:WaitForChild("InRound")

Inround.Changed:Connect(function()
	local cam = game.Workspace.CurrentCamera
	if Inround.Value then
		cam.CameraType = "Scriptable"
		runService.Heartbeat:Connect(function()
			cam.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.Angles(0,0,0) + CFrame.Angles(0,90,0) + Vector3.new(0,3,5)
		end)
	else
		cam.CameraType = "Custom"
		cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	end
end)

I get what the error is, the error is that I can’t connect that:

 CFrame.Angles(0,90,0) + Vector3.new(0,3,5)

but I don’t know how to solve it.
what I want to do is simply add CFrame.Angles(0,90,0) and also Vector3.new(0,3,5) (Position) to the same CFrame.

1 Like

Vector3 and CFrame are 2 different data types.

To accomplish this, try multiplying two CFrame instead. When you want to specify a position with CFrames, try the following:

CFrame.Angles(0,90,0) * CFrame.new(0,3,5)

This indicates a rotation and a movement of 3 units up on the Y axis and 5 units forward on the Z axis.

1 Like

I want the CFrame of the player + CFrame.new(0,3,5)…

Has the error been fixed with the CFrame correction?

nope. I still get this error if you mean

cam.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.Angles(0,0,0) + CFrame.Angles(0,90,0) * CFrame.new(0,3,5)

instead of

cam.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.Angles(0,0,0) + CFrame.Angles(0,90,0) + Vector3.new(0,3,5)

First, you need to focus on solving invalid code before getting a desired result.

As I stated before, if you use CFrame, you need to multiply them. CFrame is a matrix, unlike Vector3 being 3 numerical numbers. A CFrame is a 3x3 matrix. You can read about them here.

If you want the short answer, as I stated before, you need to multiply a CFrame with a CFrame. You can’t add CFrames together or add a Vector3 to a CFrame.

You should also consider the order of your CFrame multiplication, as it can impact your end result.

Lets break down what you’re trying to accomplish.

local rootCFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
local rotation = CFrame.Angles(0, math.rad(90), 0) -- Use radian if specifying degrees
local offset = CFrame.new(0, 3, 5)

cam.CFrame = rootCFrame * rotation * offset

That should set the camera CFrame to the HumanoidRootPart CFrame. Then, rotate it by 90 degrees and offset it by 3 units up on the Y axis and 5 units forward on the Z axis.

1 Like

there is no error but there is a problems.
when the player presses “a” key the camera rotates with the player.
I want the camera to have the same rotation all the time.

I tried a bunch of camera types “fixed”, “track”, “follow” and others but they all have the same problem

If you want to constantly have the camera behind the player, you need to constantly update the CFrame to the player’s position. It can be done with a loop, event or frame update.

However, I think there’s a simpler solution for your problem.

Set the Camera’s CameraType property to attached. This will indicate ROBLOX’s engine to follow and rotate the Camera with its subject.

You can set the CameraOffset property in the player’s humanoid to (0, 3, 5).

All you’d need to do from then, is disable the zoom functionality.

All you’d need to do from then, is disable the zoom functionality.

but how

There’s many solutions to this problem. You’d have to research the new ones we just discussed.

The one with the most control would be to set the CameraType property to Scriptable and calculate the CFrame every frame update.

Check out BindToRenderStep.

I don’t understand what you’re trying to accomplish with ‘a’ being pressed. Does it lock onto the player or set the rotation to the player’s rotation? Or does it just rotate the camera towards the player?

yes. but as I said

when the player presses “a” key the camera rotates with the player.

that’s the only thing I need to fix

@Exeplex
In the Custom camera, when the player presses “a” or “d”, the player changes x position,
that what I want to achieve.
but in the scriptable camera type when the player presses “a” or “d” the camera rotation changing.

Has this been solved? If not there are a bunch of different more better solutions that you would probably need. If you want the Camera to be at the same offset and rotation all the time it would be better to use this

local Offset = Vector3.new(0,5,10)  -- this is in world space
Camera.CFrame = HRP.CFrame + Offset 

If you want the Offset from the player to camera to remain the same use PointToWorldSpace instead.

2 Likes