Getting camera to stay in 'locked' position while still following the character

This kinda what I am aiming for, however at the end you can see, I can just use the mouse to rotate camera view, etc. I want it locked looking at the player and following the player as it moves left right, up down, but it should never rotate

com-video-to-gif%20(1)

What I tried is to set it to the players character, but that didn’t really work



-- Setting the camera while the transition UI is blocking players view
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Character.PrimaryPart.CFrame
2 Likes

You have to update the camera’s cframe, preferably using runservice.

Based on your needs all you really need to do is to offset the camera from the character’s position and make sure it is rotated the right way.That should look something like this:

local RS = game:GetService("RunService")
function EnterRoomCamera()
      Camera.CameraType = Enum.CameraType.Scriptable
      RS:BindToRenderStepped("RoomCameraUpdate",Enum.RenderPriority.Camera.Value + 1,function() 
              Camera.CFrame = CFrame.Angles(0,someAngle,0) + Character.HumanoidRootPart.CFrame.Position + AnOffset
       end)
end

You would need to set the rotation so that it is facing the room. If you want it so that the camera goes back to normal when they leave the room, just unbind the function using the :UnbindMethod and the id. The offset is a vector3 which would position the camera off of the humanoid root part. You would need to adjust that so the camera is positioned correctly relative to the humanoid root part.

1 Like

Would this mean that all my room have to be orientated in a specific way? So like the ‘4th wall’ has to face a specific direction for each room?

1 Like

If that’s easiest yes. Although there are other options such as specifying the direction and offset for each room and then having the function use those. Depends on how players go to the rooms and where they are placed.

2 Likes

bad argument #2 to ‘?’ (Vector3 expected, got number)

Camera.CFrame = CFrame.Angles(0, 0, 0) + Character.HumanoidRootPart.CFrame.Position + 15
1 Like

You’re adding a number (15) to a Vector3 (Character.HumanoidRootPart.CFrame.Position) which won’t work. Like how Waffle had it above you can define a Vector3 offset and add that instead:

local AnOffset = Vector3.new(0, 15, 0) -- Whatever offset you're looking for
Camera.CFrame = CFrame.Angles(0,someAngle,0) + Character.HumanoidRootPart.CFrame.Position + AnOffset
2 Likes

Ahh ok, is there anyway to do it without the CFrame.Angles? Cause the camera seems to point the correct way

Camera.CFrame = Character.HumanoidRootPart.CFrame.Position + Vector3.new(0, 15, 0)

How it looks, but the camera stays locked in this spot, doesnt move with the player



And I get this error
[bad argument #3 to ‘CFrame’ (CFrame expected, got Vector3)]

1 Like

Your error would be solved by changing your code a bit to this:

Camera.CFrame = CFrame.new(Character.HumanoidRootPart.CFrame.Position + Vector3.new(0, 15, 0))

You can’t set CFrame to a non-CFrame value, so you have to turn the Vector3 into a CFrame

2 Likes