Im trying to make a first person game but i need a custom camera. How can i set the cframe of the camera to the position of the player while letting it rotate like a normal first person camera?
local lookAt1 function updatecam() local delta = uis:GetMouseDelta() local x = delta.X local y = delta.Y local pos = CFrame.new(character.HumanoidRootPart.Position) if Mouse2Hold == true then lookAt1 = CFrame.Angles(math.rad(-y),math.rad(0),math.rad(-x)) cam.CFrame = cam.CFrame * lookAt1 * pos --this is where i need help else lookAt1 = CFrame.Angles(math.rad(-y),math.rad(-x),math.rad(0)) cam.CFrame = cam.CFrame * lookAt1 * pos --this is where i need help end end
The issues that i need help with are due to needing to set the cframe in one line as far as i know. This means that if i remove the
cam.CFrame = lookAt1 * pos
then the position of the camera would work fine, but the rotation messes up, due to the rotation setting back to 0 after every frame and not maintaining its previous values. However if i keep it as it was above then the rotation works perfectly but the camera flies backwards, due to it keeping its previous position value while still adding the players current location on to it. For example if the players X is at 10 then it would just keep adding that on to itself and putting the camera at that new coordinate (the player never actually moves), meaning it would be 10, then 20, then 30, and so on every frame.
That was long winded but its the best I can explain it. TLDR I need cam.CFrame * lookAt1 but i cant also have it multiplying the pos by cam.CFrame
local player = game.Players.LocalPlayer player.CameraMode = Enum.CameraMode.LockFirstPerson