✓ Accepted answer
Hello! I see that you are facing troubles using camera. Well that is no problem because I am here to help.
What you have here is pretty much right, you are just missing one vital thing. Whenever you want to manipulate the camera with your scripts, you must change the CameraType. CameraType is a property of camera that changes around how the camera behaves. In order to move the camera on to the side of the play you must use the "Scriptable" type. So using your code here, we are going to edit it a bit:
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character
while cam.CameraSubject == nil do
wait(1)
end
cam.CameraType = "Scriptable"
while wait() do
cam.CFrame = cam.CameraSubject.Parent.UpperTorso.CFrame * CFrame.new(Vector3.new(5,0,0))
end
Now technically, that would make your code work just as intended, but I'm going to help you out with a few edits. First off, we are going to implement RenderStepped. RenderStepped fires every time a new frame is rendered. This means that to get the smoothest camera action, we would want to use it because it happens e very frame rather than every .03 seconds. Another thing is that you are linking the camera to the upper torso. This creates a very jittery camera motion because it's cframing relative to the UpperTorso, and the UpperTorso moves because of animations. To combat this we can simply use the Character's HumanoidRootPart as the reference point.
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character
while cam.CameraSubject == nil do
wait(1)
end
cam.CameraType = "Scriptable"
game:GetService("RunService").RenderStepped:connect(function()
cam.CFrame = cam.CameraSubject.Parent.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(5,0,3))
end
Also your camera was only off to the side, so I also moved it back on the Z axis 3 ish studs, but feel free to edit that around until it's comfortable for you :D
Thus creates a nifty camera system.
I hope my answered helped
~Lone
1 comment
So.. I have another problem related to this post, and I need the player to look towards the mouse, like in the first person view, but still be in first person. I tried using
CameraModeunder Humanoid and set it to LockFirstPerson, it worked, but if you tried to zoom in, you get stuck in first person.