Problem with the smooth camera

Hello everyone! I am currently working on my game and want to make a nice and smooth 3rd person camera. An example of such a smooth camera is shown here

In this example I move the camera and as you can see the camera moves smoothly with a slight deceleration. This example is taken from the game Little Nightmares 2.

You can also see a good example of such a smooth camera here

https://www.roblox.com/games/3907722122/SCP-Anomaly-Breach

Please tell me how I can implement this. At this point, I know what might be here :Lerp()

UPD: Guys, please, if you know the solutions, you can write here for other developers. But I have already been helped under my other post!!!

2 Likes

Hey there. I made a post a while back on the use of springs to achieve the desired effect. There is also a video which goes into more detail on it from an RDC panel.

In effect:

2 Likes

Thanks! I think there is a lot of useful information here that will help me in implementing my plan

1 Like

I also want to ask, what is the best way to put a spring in the camera script from behind the shoulder?
Here is the script itself

local uis = game:GetService("UserInputService")

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local RunService = game:GetService("RunService")

local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
humanoid.AutoRotate = false

local hrp = char:WaitForChild("HumanoidRootPart")
local x = 0
local y = 0

local cameraPos = Vector3.new(2, 2, 8)

uis.InputChanged:Connect(function(input, processed)
	if processed then return end
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		x = x - input.Delta.X*0.1
		y = math.clamp(y - input.Delta.Y*0.1, -65, 65)
		hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(-input.Delta.X), 0)
	end
end)

RunService.RenderStepped:Connect(function()
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter

	local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
	local cameraCFrameGoal = startCFrame:ToWorldSpace(CFrame.new(cameraPos.X, cameraPos.Y, cameraPos.Z))
	local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(cameraPos.X, cameraPos.Y, -10000))
	camera.CFrame = CFrame.new(cameraCFrameGoal.Position, cameraDirection.Position)

end)

Take a look at this. Comments explaining what I’ve done.

local Spring = require(script:WaitForChild("Spring"))

--[[
	Creating a new spring
]]
local spring = Spring.new(Vector3.new())

--[[
	Adjsut the dampening and speed values to your liking - 
	see the post I linked which contains a comment
	in the code explaining how changing the values affects 
	the spring.
]]
spring.d = 100
spring.s = 10

local uis = game:GetService("UserInputService")

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local RunService = game:GetService("RunService")

local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
humanoid.AutoRotate = false

local hrp = char:WaitForChild("HumanoidRootPart")
local x = 0
local y = 0

local cameraPos = Vector3.new(2, 2, 8)

uis.InputChanged:Connect(function(input, processed)
	if processed then return end
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		x = x - input.Delta.X*0.1
		y = math.clamp(y - input.Delta.Y*0.1, -65, 65)
		hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(-input.Delta.X), 0)
	end
end)

RunService.RenderStepped:Connect(function()
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter

	local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
	local cameraCFrameGoal = startCFrame:ToWorldSpace(CFrame.new(cameraPos.X, cameraPos.Y, cameraPos.Z))
	local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(cameraPos.X, cameraPos.Y, -10000))
	
	--[[
		Set the spring target to your CFrame goal which you've calculated,
	]]
	spring.t = cameraCFrameGoal.Position
	
	--[[
		Then set the position vector of the CFrame as the current spring
		position.
	]]
	camera.CFrame = CFrame.new(spring.p, cameraDirection.Position)
end)
2 Likes

Now I understand! Thank you very much

1 Like

Is there any article about using springs? When I woke up today, I realized that I didn’t understand anything about springs :frowning_face:. In your example, there was an example with a car in this message. But I would like it to be the same as you have in the example above

How do i fix the camera being able to clip through walls and i can’t zoom out or in