I can't understand Camera using CFrame

Hi, everyone!
I create this subject today so you can help me with an effect I cannot understand.

I’ve studied how CFrame works, and I kind of get it with instances such as Parts, however, it won’t work with the Camera.

Take a look at this:

As you can see in the previous video, when I click the BLOCK button, the block’s CFrame is edited to be equivalent to the CFrame of the player’s HumanoidRootPart (HRP). That’s exactly the result I wondered to reach.

Here’s my LocalScript:

local player = game:GetService("Players").LocalPlayer
local hrp = player.Character:WaitForChild("HumanoidRootPart")

script.Parent.MouseButton1Click:Connect(function()
	workspace.Block.CFrame = hrp.CFrame
end)

However, when I click the CAM button, it doesn’t produce the same effect: the Camera is well set to the same orientation as the HRP, but not at the same position.

Here’s my LocalScript:

local player = game:GetService("Players").LocalPlayer
local hrp = player.Character:WaitForChild("HumanoidRootPart")

script.Parent.MouseButton1Click:Connect(function()
	workspace.CurrentCamera.CFrame = hrp.CFrame
end)

I know there’s not such an interest in setting the Camera’s CFrame to the HRP, but I still wonder why, even the LocalScript is exactly the same, it won’t do the same with the Part and the Camera.
Note: I’ve tried to do this:

workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable

but it changed absolutly nothing.

Could someone explain me why it’s different?
I’ll be grateful for any comment!
Have a great day!

1 Like

Try this

1 Like

This doesn’t work at all for me:
the camera doesn’t follow the subject anymore.

As I said, the angle of the Camera is perfectly set, there’s only a problem with the position of the Camera. However, I even don’t know if it’s a problem, and if it’s not, I’d like to know why, that’s it.

Maybe the Camera’s properties are different than Parts’ properties ?

1 Like

Because you are setting the camera CFrame, camera doesn’t follows the part, you have to update it to the Part CFrame manually. You can do this by using GetPropertyChangedSignal(“CFrame”).

local cameraFollowing = false --Make this true when you are following the part CFrame
workspace.Block:GetPropertyChangedSignal("CFrame"):Connect(function()
    if cameraFollowing == true then
        workspace.CurrentCamera.CFrame = workspace.Block.CFrame
    end
end)

And yes, camera properties is different.

1 Like

Well, what I want to achieve is pretty easy: I just want to set the Camera in a certain position and orientation. For this, I set the Camera to the HRP’s CFrame and that perfectly works.

What I’d like to know, is why the Camera’s CFrame isn’t the same as the Block’s CFrame after we clicked on both buttons.

I don’t understand, are you asking why the camera location doesn’t change when you press the camera button first and then the block button?

You are setting the CFrame, if you want it to follow the part you have to set the CFrame again when the part position is changed.

You can do this by using the code I write above.

So you still want the camera to follow while changing the position?

Have you tried the other camera types such as Track, Watch, and Attach?

You should also consider looking at the default player scripts as the camera CFrame is usuallu Overwritten there on a renderstepped loop so you might need to mess with renderstep priority.

In fact, I don’t want to achieve anything at all. I’ve got what I wanted to.
However, I wonder why, when I click the CAM button, then the Camera doesn’t go at the same CFrame than the Block when I click the BLOCK button.
That’s it, I don’t need any script, I just don’t understand why, with my script, it doesn’t result to the same thing while both of my LocalScripts are similar (even almost equal to each other).

Do you understand better what I want to know from now?
I hope I could help you better understanding my problem.

Because it doesn’t follows the part, you aren’t doing something about the part. You are using the parts’ CFrame.

Odd, because it should be working.
Looking at the video you provided, the camera remains in their Enum.Cameratype = 3 state.
The last reason I can think something goes wrong is because it needs to be a LocalScript in the StarterPlayerScripts. Otherwise, troubleshoot into changing the camera type even if you already tried.

If needed, I made a quick working example with code and video showcasing the end result.

Example

Location: StarterPlayer -> StarterPlayerScripts -> LocalScript

--//SERVICE
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
--//VARIABLES
local player = Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
--//CODE
UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.E then --pressing E will move the camera to the HRP CFrame
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = player.Character.HumanoidRootPart.CFrame
	elseif key.KeyCode == Enum.KeyCode.Q then --pressing Q will refresh to original camera position
		camera.CameraType = 3
	end
end)

End result:

1 Like

I’m very grateful for your help!

Your comment grealty helps me better understanding how to achieve such a work.
Have a great day!

The problem seems to be the CameraMode property, because in your script, it does perfectly what’s expected.

1 Like

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