I am trying to create a realistic handheld camera effect for my horror game. Everything is set, only the cherry on top is missing: changing the camera orientation. My camera system already replicates realistic rotation (x,y in 2d axis) and more, but the effect is not enough if the camera doesn’t move left or right / up and down.
Video is down below!
What I have already achieved: This code below almost already creates the desired effect, but it seems robotic, I WANT IT TO BE CONTINUOUS!*
-- Local script on StarterChar
local RS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local mouse = game.Players.LocalPlayer:GetMouse()
local tweenService = game:GetService("TweenService")
local tweenTime = 3
local tweenInfo = TweenInfo.new(tweenTime, Enum.EasingStyle.Back, Enum.EasingDirection.InOut,0,true)
local targetCFrame = camera.CFrame
local isTweening = false
local random = Random.new()
local function getNewVals(currentCamCFrame) -- Get new target for the tweening
local multiplier = random:NextInteger(1.1, 1.6) -- Adjust multiplier range as needed
local randomAngleX = math.rad(random:NextInteger(-2,2)) -- Random angle for variation
local randomAngleY = math.rad(random:NextInteger(-2,2)) -- Random angle for variation
local newVal = currentCamCFrame * CFrame.fromEulerAnglesXYZ(randomAngleX * multiplier, randomAngleY * multiplier, 0)
return newVal
end
local tween
local fullStop = false
local idle = false
local function tweenCam() -- Tween cam duhh
tween = tweenService:Create(camera, tweenInfo, { CFrame = targetCFrame })
tween:Play()
isTweening = true
tween.Completed:Connect(function()
if fullStop == false then
isTweening = false
targetCFrame = getNewVals(camera.CFrame) -- Generate new target CFrame after each tween
tweenCam() -- Initiate the next tween
end
end)
end
UIS.InputChanged:Connect(function(input, isTyping) -- Stop tweening if mouse has moved
if isTyping then return end
if input.UserInputType == Enum.UserInputType.MouseMovement then
if isTweening == true then
isTweening = false
fullStop = true
tween:Cancel()
idle = false
warn("Full stop!")
end
end
end)
mouse.Idle:Connect(function() -- Start tweening if idle
if idle == false then
idle = true
task.wait(2)
fullStop = false
targetCFrame = getNewVals(camera.CFrame) -- Generate initial target CFrame
tweenCam()
warn("Idle!")
end
end)
Here’s how it looks like:
How would I go about on making it continuous (i.e., the it will tween to a new target before the previous one finishes)? I tried lerping but I can’t seem to do it. Especially since I want the tweening/lerping to have a new targetCFrame at 0.9 (90% or almost finished tweening or 0.9 alpha for lerping).