Ad
Log in to vote
0

Camera "breaks" when attempting to increase view from 80 degrees to 90 degrees?

Asked by
ShowJa 0
3 days ago

So essentially I'm trying to create a camera that allows the player to look up or down 90 degrees. I'm having some issues with this however, as whenever I modify the built-in camera system for roblox to go beyond the maximium of 80 degrees, it breaks and starts spinning everywhere.

local MIN_Y = math.rad(-90)
local MAX_Y = math.rad(90)

function BaseCamera:CalculateNewLookCFrameFromArg(suppliedLookVector: Vector3?, rotateInput: Vector2): CFrame
    local currLookVector: Vector3 = suppliedLookVector or self:GetCameraLookVector()
    local currPitchAngle = math.asin(currLookVector.y)
    local yTheta = math.clamp(rotateInput.y, -MAX_Y + currPitchAngle, -MIN_Y + currPitchAngle)
    local constrainedRotateInput = Vector2.new(rotateInput.x, yTheta)
    local startCFrame = CFrame.new(ZERO_VECTOR3, currLookVector)
    local newLookCFrame = CFrame.Angles(0, -constrainedRotateInput.x, 0) * startCFrame * CFrame.Angles(-constrainedRotateInput.y,0,0)
    return newLookCFrame
end
--ALL OF THIS CODE IS FROM ROBLOX THEMSELVES. I'M JUST TRYING TO MODIFY IT FOR MY NEEDS.

This code is from the player.playerscripts.PlayerModule.CameraModule.BaseCamera script.

For some reason, whenever I unlock it, the camera just starts to spin whenever that value is reached. It happens for any value above 81 degrees, and is really annoying.

Answer this question