#Introduction

I created this LocalScript inside of the StarterGui that would shake the camera. However, I feel like the camera is shaking too roughly and I want it to lerp to the random position smoothly.

#Script

Here's my script:

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild('Humanoid')

function shakeCam()
	for i = 1,20,1 do
		local a = math.random(-100,100)/100
		local b = math.random(-100,100)/100
		local c = math.random(-100,100)/100
		hum.CameraOffset = Vector3.new(a,b,c)
		wait()
	end
end

game:GetService("UserInputService").InputBegan:Connect(function(keyCode)
	if keyCode.keyCode == Enum.KeyCode.F then
		shakeCam()
		hum.CameraOffset = Vector3.new(0,0,0)
	end
end)

#Conclusion / Problem

Everything is working and all, but I want the camera to smoothly transition to the a,b and c's position.

EDIT: This thread is now closed, I no longer have interest in it. Thank you all for answering my questions!

I have no idea on how I would do this, mostly because I just learned :Lerp().

Any help please?

6 comments

0

Have you tried assigning the camera to a part then using tweenservice on the part? I'll guess that'd make it more 'smooth' for what you're seeking for.

0

No no... You don't get it. The function of shakeCam() is to shake the camera, not have the camera manipulated somewhere else.

0

Are you trying to smoothen it as for it to Tween? Or are you just trying for it to just be more smooth?

0

I think if you change the 'wait()' to 'game:GetService("RunService").RenderStepped:Wait()' will got some more Smoothly

0

I wasn't implying that you needed the camera manipulated somewhere else, anyways the best you have is to try and use tweenservice on the camera.

0

How exactly would I do that?