Hello, so as you know robloxs fp cam(first person cam) isnt the height of game cameras. Currently, I have a camera bobbing system, and a raycasting offset system. But, the turning isnt so smooth. Is it possible to use tweens to turn the camera? Not for cutscenes, but for a regular game camera. Kinda like this: ROBLOX DOORS - Entity Concept: STALK | By Mekbok - YouTube Here is my current code:
local function initgamecam()
onchartrans()
local humrootpart = Character:WaitForChild("HumanoidRootPart")
local hum:Humanoid = Character:WaitForChild("Humanoid")
local tiltSpeedZ = 0.1
local bobbingSpeed = 0.13
cam.CameraSubject = Character.Humanoid
cam.CFrame = Character.PrimaryPart.CFrame
Player.CameraMode = Enum.CameraMode.LockFirstPerson
cam.CameraType = Enum.CameraType.Custom
local runService = game:GetService("RunService")
--onchartrans()
local lastcamcf = nil
local tweenplaying = false
camclipfix = RunService.RenderStepped:Connect(function()
local ignore = RaycastParams.new()
ignore.FilterType = Enum.RaycastFilterType.Exclude
ignore.FilterDescendantsInstances = Character:GetChildren()
local camray = workspace:Raycast(Character.char.Position, ((Character.char.CFrame + Character.char.CFrame.LookVector * 2) - Character.char.Position).Position.Unit)
if camray then
Character.Humanoid.CameraOffset = Vector3.new(0, 1, - (Character.char.Position - camray.Position).Magnitude)
else
hum.CameraOffset = Vector3.new(0,-0.5,-0.5)
end
end)
local tilt = 0
local sinValue = 0
local function lerp(a, b, t)
return a + (b - a) * t
end
local function calculateSine(speed, intensity)
sinValue += speed
if sinValue > (math.pi * 2) then sinValue = 0 end
local sineY = intensity * math.sin(2 * sinValue)
local sineX = intensity * math.sin(sinValue)
local sineCFrame = CFrame.new(sineX, sineY, 0)
return sineCFrame
end
local previousSineX = 0
local previousSineY = 0
cambobconnect = runService.RenderStepped:Connect(function(dt)
local movementVector = cam.CFrame:vectorToObjectSpace(humrootpart.Velocity / math.max(hum.WalkSpeed, 0.01))
local speedModifier = (hum.WalkSpeed / 16)
tilt = math.clamp(lerp(tilt, movementVector.X * tiltSpeedZ, 0.1), -0.05, 0.1) / 2
local sineCFrame = calculateSine(bobbingSpeed * speedModifier, movementVector.Z * speedModifier)
local lerpedSineX = lerp(previousSineX, sineCFrame.X, 0.1)/2
local lerpedSineY = lerp(previousSineY, sineCFrame.Y, 0.1)
cam.CFrame *= CFrame.Angles(0, 0, tilt) * CFrame.new(lerpedSineX, lerpedSineY, 0)
previousSineX = lerpedSineX
previousSineY = lerpedSineY
end)
end
Heres my character layout:
Thanks!