How would I create camera tilting in my game?

How would I create camera tilting similar to this game:

Im trying to make a fast paste combat game
but I just don’t know where to go when creating camera tilt

Please don’t send me entire lines of code but just an example
of how to set the tilt

1 Like

This script adjusts the camera’s roll based on the player’s move direction. By calculating the roll angle using the dot product of the camera’s right vector and the character’s move direction, you can increase the Intensity variable for more tilting.

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Camera = workspace.CurrentCamera

local Intensity = 2 -- increase it for more tilting

local function GetRollAngle()
	local Character = Player.Character
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	return -Camera.CFrame.RightVector:Dot(Humanoid.MoveDirection)
end

RunService:BindToRenderStep("RotateCamera", Enum.RenderPriority.Camera.Value + 1, function()
	local Roll = GetRollAngle() * Intensity
	local Rot = CFrame.Angles(0, 0, math.rad(Roll))
	Camera.CFrame = Camera.CFrame * Rot
end)
1 Like

Do I have to lerp the Camera CFrame to make it smooth?

And how do I make it tilt forward?

1 Like

For smoothness you can use the lerp function like this:

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Camera = workspace.CurrentCamera

local Intensity = 2 -- increase it for more tilting
local Smoothness = 0.1 -- increase it for smoothness

local currentRoll = 0

local function GetRollAngle()
	local Character = Player.Character
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	return -Camera.CFrame.RightVector:Dot(Humanoid.MoveDirection)
end

function lerp(a, b, t)
	return a + (b - a) * t
end

RunService:BindToRenderStep("RotateCamera", Enum.RenderPriority.Camera.Value + 1, function()
	local targetRoll = GetRollAngle() * Intensity

	local currentRoll = lerp(currentRoll,targetRoll,Smoothness)

	local Rot = CFrame.Angles(0, 0, math.rad(currentRoll))
	Camera.CFrame = Camera.CFrame * Rot
end)

and for the forward tilt it is gonna be the same function as GetRollAngle() but for LookVector Instead of RightVector

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.