You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I’m trying to make a wallrun code and whenever the player starts wallrunning, I want the camera to rotate to give some sense of immersion. -
What is the issue? Include screenshots / videos if possible!
At times the code works just as intended. I try to clamp the Z-rotation between -11.25 degrees and 11.25 degrees. But, some times, it randomly goes beyond -180;180, turning the camera upside down? Here’s a video snippet:
https://youtu.be/uQqV5SmQlRA -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to look for solutions online, but none of them worked with Roblox’s Lua. And none of the past issues about camera tilting gave me some new information to work with.
this is a snippet of the code. yes, the side == "Right"/"Left"
always is correct, I skipped over the raycasting portion since that isn’t relevant to the issue.
local function onWallrunCameraTiltingRenderStep(delta:number)
local pos:Vector3 = camera.CFrame.Position
local xRotation:number, yRotation:number = camera.CFrame:ToEulerAnglesXYZ()
--CodeCodeCode
if math.abs(wallrunCameraTilt) < maxWallrunCameraTilt
and character.Humanoid:GetState() == Enum.HumanoidStateType.Freefall
and side == "Right"
then
wallrunCameraTilt += delta*maxWallrunCameraTilt
wallrunCameraTilt = math.clamp(wallrunCameraTilt, 0, 90)
elseif math.abs(wallrunCameraTilt) < maxWallrunCameraTilt
and character.Humanoid:GetState() == Enum.HumanoidStateType.Freefall
and side == "Left"
then
wallrunCameraTilt -= delta*maxWallrunCameraTilt
wallrunCameraTilt = math.clamp(wallrunCameraTilt, -90, 0)
end
if wallrunCameraTilt > 0
and side == "Nil"
then
wallrunCameraTilt -= delta*maxWallrunCameraTilt*2
if wallrunCameraTilt < .5 then
wallrunCameraTilt = 0
end
elseif wallrunCameraTilt < 0
and side == "Nil"
then
wallrunCameraTilt += delta*maxWallrunCameraTilt*2
if wallrunCameraTilt > .5 then
wallrunCameraTilt = 0
end
end
if wallrunCameraTilt ~= 0 then
camera.CFrame = CFrame.new(pos)*CFrame.Angles(xRotation,yRotation,math.rad(wallrunCameraTilt))
local _:number,_:number,adjustedZ:number = camera.CFrame:ToEulerAnglesXYZ()
print("So, Z",adjustedZ)
adjustedZ = math.clamp(adjustedZ, -math.rad(maxWallrunCameraTilt), math.rad(maxWallrunCameraTilt)) --maxWallrunCameraTilt = 11.25
camera.CFrame = CFrame.new(pos)*CFrame.Angles(xRotation,yRotation,adjustedZ)
end
end --End of renderstepped
-- some other code here
RunService:BindToRenderStep("WallrunCameraTilting", Enum.RenderPriority.Camera.Value + 1, onWallrunCameraTiltingRenderStep)
I am really inexperienced when it comes to camera manipulation, let alone anything that requires rotations . I’d be grateful for anyone who has any idea on what could be the issue and on how to fix it.