As you can see, the camera tilts towards the direction you turn.
The problem with this is that it takes in the MouseInput, which only works for PC users. On mobile and console, this feature does not work. I am wondering if theres an alternative to what I’m doing here:
It doesn’t look like there’s a way to do it through the ContextActionService, or at least not an obvious one. Maybe Enum.UserInputType.Touch, but I don’t think so.
You could also detect the angle the camera changed in the Y axis in the last frame, if you want:
local cam = workspace.CurrentCamera
local function Flatten(vec: Vector3): Vector2
return Vector2.new(vec.X, vec.Z).Unit
end
local lastDir = Flatten(cam.CFrame.LookVector)
local function ReadCameraDelta()
local dir = Flatten(cam.CFrame.LookVector)
-- positive for clockwise rotations, negative for ccw
local angle = math.asin(lastDir:Cross(dir))
print(string.format("angle change = %d", math.deg(angle)))
lastDir = dir
end
game:GetService("RunService"):BindToRenderStep("UpdateCamera", Enum.RenderPriority.Camera.Value + 1, ReadCameraDelta)
But a input-based method would probably be better for your application.
(Sorry if the orginization looks like a war crime)
local function Flatten(vec: Vector3,vector1:string,vector2:string): Vector2
#turning vector 3 into vector two
return Vector2.new(vec[vector1], vec[vector2]).Unit
end
local function Lerp(a, b, m)
return a + (b - a) * m
end
local lastDirZ = Flatten(camera.CFrame.LookVector,"X","Z")
local lastDirY = Flatten(camera.CFrame.LookVector,"Z","Y")
local angleX
local angleY
local function ReadCameraDelta()
local dir = Flatten(camera.CFrame.LookVector,"X","Z")
local dir2 = Flatten(camera.CFrame.LookVector,"Z","Y")
-- positive for clockwise rotations, negative for ccw
angleX = math.asin(lastDirZ:Cross(dir))
angleY = math.asin(lastDirY:Cross(dir2))
angleX = math.deg(angleX)
angleY = math.deg(angleY)
print(string.format("angle change X = %d", math.deg(angleX )))
print(string.format("angle change Y = %d", math.deg(angleY )))
lastDirZ = dir
lastDirY = dir2
end