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)
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
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()
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)