Any way i can make this movement smooth?

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:

Script

local camera = workspace.Camera

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

local runService = game:GetService("RunService")

runService.RenderStepped:connect(function()
	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.new(camera.CFrame.Position) * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(2))
		end
		if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.D) then
			a = true
			camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(-2))
		end
		if a == false then
			camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x,y,z)
		end
	end
end)

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

Video

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.

pls help this is serious

1 Like

https://developer.roblox.com/en-us/api-reference/class/Tween

hard solution to find i know
but anyway tweens are like super good because if you make a new tween the old one will get rewritten automatically. you could also use AlignOrientation i guess but this is really convenient

game:GetService("TweenService"):Create(camera, TweenInfo.new(0.4) {camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(2))}):Play()

Yeah, i thought on using Tween Service, but the problem is i don’t know how i could rotate the camera with tween service.

Gonna try your solution and see if it works.

This might help!

Yeah, I already read about cframe, but the problem here is, i don’t know how to mix:

CFrame
TweenService
Camera

And that almost works, but now we have another problem :
robloxapp-20220517-1955021.wmv (817.9 KB)

You can use TweenService to animate the Camera’s CFrame, just like any other writeable property of any instance. As long as the property can be lerped (transitioned) like Numbers, Colors, Vector3s, CFrames, etc, you can tween it.

local NewCFrame = workspace.CurrentCamera.CFrame  -- Take the Current CFrame
   + (workspace.CurrentCamera.CFrame.LookVector * 3)  -- And offset it by 3 studs forward in the direction the camera is looking

game.TweenService:Create(workspace.CurrentCamera, TweenInfo.new(1), {CFrame = NewCFrame}):Play()

So yeah, the guy before you comment, send me this script, but as you can see in the video i sent, the camera like, teleports.

game:GetService("TweenService"):Create(camera, TweenInfo.new(0.4), {CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(x,y,z) * CFrame.Angles(0,0,math.rad(2))}):Play()

And i don’t know why that happens, because in my vision everything is right…

Tweening isn’t what you need here, Tweens should only be used on non moving objects (Mostly).
Tweens take the start position, and interpolate that to the end over x amount of seconds with whatever other parameters.

What we need is Lerping, check to see the character’s move direction and compare that to the Root’s Right Vector with a dot product. Then we lerp that dot product multiplied by X to get the camera tilt.

local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Character:WaitForChild("HumanoidRootPart")
Character:WaitForChild("Humanoid")

local Camera = workspace.CurrentCamera

local SideStep = 0
local StepAmount = 5

function Lerp(A, B, C)
return A + (B - A) * C
end

RunService.RenderStepped:Connect(function(Delta)
local RightVector = Character.HumanoidRootPart.CFrame.RightVector
local MoveDirection = Character.Humanoid.MoveDirection

local DotProduct = -RightVector:Dot(MoveDirection) * StepAmount
SideStep = Lerp(SideStep, DotProduct, Delta * 20)

Camera.CFrame = Camera.CFrame * CFrame.Angles(0, 0, math.rad(SideStep))
end)