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.
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.
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.
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.
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?
@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.