Hi, i’m back on devforum, waiting for help again! Well anyway about that, I need help on my realistic first person camera. How can I make the camera smoother?
Script in StarterPlayerScripts:
local oldCamCFrame
local plr = game.Players.LocalPlayer
local char = plr.CharacterAdded:wait()
local hum = char:WaitForChild("Humanoid")
local cam = workspace.CurrentCamera
local animation = hum:LoadAnimation(script.Animation)
game.ReplicatedStorage.ToClient.OnClientEvent:Connect(function()
animation:Play()
local Function = game:GetService("RunService").RenderStepped:Connect(function() -- function that loops
local CamCFrame
if hum.RigType == Enum.HumanoidRigType.R15 then -- if it's r15 then
CamCFrame = char.Head.CFrame:ToObjectSpace(char.UpperTorso.CFrame)
elseif hum.RigType == Enum.HumanoidRigType.R6 then -- if it's r6 then
CamCFrame = char.Head.CFrame:ToObjectSpace(char.Torso.CFrame)
end
if oldCamCFrame then
local _,_,z = CamCFrame:ToOrientation()
local x,y,_ = CamCFrame:ToObjectSpace(oldCamCFrame):ToEulerAnglesXYZ()
cam.CFrame = cam.CFrame * CFrame.Angles(x,y,z)
end
oldCamCFrame = CamCFrame
end)
repeat wait() until animation.IsPlaying == false
Function:Disconnect()
end)
Note: You can try out the script to see the problem by only just copying the variables and the renderstep.