I have been trying to make a script for rotating the camera for a while now to no avail, I could just use camera offset but I would like for the camera to tilt too.
The camera simply doesnt budge on the z axis, nothing seems to work other than using the scriptable type which doesn’t follow the head.
Seems to work but not, it wants to rotate but it fights back and doesn’t quite do it, it rotates like 1 degrees and pushes back, if i make it rotate 100 then it is quite visibly shaking.
I saw another script which puts the camera into scriptable mode and then rotates it and stops the player from moving until released so it makes me wonder if its possible… But I have seen games do it before so my brain hurts.
Would you mind clarifying exactly what it is you’re looking to achieve? The original post was fairly vague so I could only provide what has worked for others before, examples in the form of images, videos etc. would be helpful.
Search the forum for similar threads and if you find any code that works hook it to the UserInputService's ‘InputBegan’ event/signal for the ‘E’ and ‘Q’ keys.
There’s plenty of ways to achieve this effect.
A way that I can think of, off the top of my head, is by using ContextActionService to bind your Q and E key to a function that handles the leaning itself. Then, you could bind a function to RenderStep that tilts your camera’s Z axis (ex. CurrentCamera.CFrame *= CFrame.Angles(0, 0, math.rad(LeanAngle))), and your character aswell.
I’d suggest reading up on ways to manipulate the character’s RootJoint C0/C1 to achieve the ‘character rotation’ effect you would like.
Would you be able to specify how many studs and degrees the camera should move and rotate respectively in response to the ‘Q’ and ‘E’ keys being pressed?
local Enumeration = Enum
local Game = game
local Workspace = workspace
local RunService = Game:GetService("RunService")
local UserInputService = Game:GetService("UserInputService")
local Camera = Workspace.CurrentCamera
local Connection
local function OnRenderStep(Input)
Camera.CFrame *= CFrame.new(if Input == "Q" then -0.5 elseif Input == "E" then 0.5 else 0, 0, 0) * CFrame.Angles(0, 0, if Input == "Q" then math.pi / 32 elseif Input == "E" then -math.pi / 32 else 0)
end
local function OnInputBegan(InputObject, GameProcessed)
if GameProcessed then return end
local Input = InputObject.KeyCode.Name
if not (Input == "Q" or Input == "E") then return end
if Connection and Connection.Connected then return end
Connection = RunService.RenderStepped:Connect(function() OnRenderStep(Input) end)
end
local function OnInputEnded(InputObject, GameProcessed)
if GameProcessed then return end
local Input = InputObject.KeyCode.Name
if not (Input == "Q" or Input == "E") then return end
if Connection then Connection:Disconnect() end
end
UserInputService.InputBegan:Connect(OnInputBegan)
UserInputService.InputEnded:Connect(OnInputEnded)
This is likely more inline with what you were trying to achieve, tweens could be implemented into this script if necessary.