Help With Physics

I need help on making this camera effect smoother

  1. What do you want to achieve?

R: “I want to make this camera effect smoother.”

  1. What is the issue?

R: “I’m not good with camera manipulating.”

  1. What solutions have you tried so far?

R: “Searching in YT, DevForum, but nothing helped.”

For anyone that wants my script to make some changes, here it is:


local camera = workspace.Camera

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:wait()

local runService = game:GetService("RunService")

	local humanoid = char:FindFirstChild("Humanoid")

	if humanoid then
		local a = false
		local x,y,z = camera.CFrame:ToEulerAnglesXYZ()
		if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.A) then
			a = true
			camera.CFrame = * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(2))
		if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.D) then
			a = true
			camera.CFrame = * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(-2))
		if a == false then
			camera.CFrame = * CFrame.Angles(x,y,z)

And here’s a video of what i have in the moment:


robloxapp-20220517-1834167.wmv (872.6 KB)

If you don’t get what i’m trying to do, i want to make the camera rotate smoothly to the sides.

i already posted this before, but i got no results/solutions

You could either use the :Lerp() function or TweenService to smoothly move it to the side.

I’m not so much familiar with the “:Lerp()” function, and using the tween service just glitches the camera, I don’t know why.

CFrame:Lerp() will work best since you are using RenderStepped.

local goalCFrame = * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(-2))
camera.CFrame = camera.CFrame:Lerp(goalCFrame, .5)

[Understanding Lerp]

Lerp means linear interpolation.
Linear in LUA refers to anything that proceeds in a straight, un-curved fashion.
Interpolation in LUA refers to inserting new data points based on pre-existing data.
So all together, Lerp means to create new consistent data based on pre-existing data.

The data we use in :Lerp() is usually CFrame.

[Lerp Syntax]
OriginalCFrame:Lerp(GoalCFrame, Alpha)
(Alpha being any number 0 - 1 that represents where we want to interpolate to)

So, if you wanted to get the CFrame halfway between the goal and the start you would do:
OriginalCFrame:Lerp(GoalCFrame, .5)

[Why it Works]
This function smooths the camera because it increases the number of CFrame points the camera must go through before reaching its destination.

The function simply takes our knowledge that adding 2 numbers together and dividing them by 2 will give us the middle point and applies it to CFrames.

Hope this helps! :slight_smile:

1 Like