Remove Look Angle Limit

Currently, when you look straight up, your camera stops and doesn’t allow you to move your head up any further. How would I make it so that I can infinitely keep moving my mouse up?

Simply put, I’m making a space game, and I don’t want there to be a down and up.
The character would be able to move wherever they’re looking.

You can fork the PlayerModule to add this, or go all out and use a custom camera controller.

This might also help you: Customizing the Camera | Documentation - Roblox Creator Hub

So it’s actually very simple, you just need to get how much the mouse moved since the last frame

So first I initialize what the X and Y will be which is zero meaning theyll be at there default, the maxAngleY is what you didn’t want but I made it 360 + 360 so that youll be able to move your camera all the way around on the Y axis, the sensitivy is how much mouse movement it takes to move the camera, the height is how far above you want the camera to be on your focusObject, and the distance is how zoomed in or out it will be on your focusObject

In the loop I get the mousedelta through UserInputService, and then I set the X we initialized previous to its current value + the mouse’s delta X * the amount of time since the last frame (dt) and then by the sensitivity

I do pretty much the same thing with the Y but I use the clamp to incorporate the maxAngleY, it’ll limit the min and max of the Y to whatever you set maxAngleY to, so just in case you may want to use this for something else

Then I set the camera’s cframe using lerp to the focus object’s position and then I use the CFrame method fromEulerAnglesYXZ to properly put the X and Y values in the right places so there no gimbal lock I think, we set them both to negative and then I multiply that by a new CFrame which incoroprates our height and our distance

Should work something like this!

local camera = workspace.CurrentCamera
local X,Y = 0,0
local maxAngleY = 360 + 360
local sensitivity = .3
local height = 1
local distance = 12
local focusObj = humrp.Position

game:GetService("RunService").Stepped:Connect(function(time, dt)

   if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) then
      UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
      local delta = UserInputService:GetMouseDelta()

      X = X + delta.X * dt * sensitivity
      Y = math.clamp(Y + delta.Y * dt * sensitivity, -math.rad(maxAngleY), math.rad(maxAngleY))
   else
      UserInputService.MouseBehavior = Enum.MouseBehavior.Default
   end

   camera.CFrame = camera.CFrame:Lerp(CFrame.new(focusObj) * CFrame.fromEulerAnglesYXZ(-Y , -X , 0) * CFrame.new(0,height, distance), dt * 15)
end)
2 Likes

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