Recently, I’ve noticed that Roblox only allows you to look up/down at around 80 degrees, last time I checked. This is a problem since players in my game cannot engage enemies directly above or below them, making some situations annoying. I have modified the camera scripts to allow for direct 90 degree up / down, however, this causes the camera to “jump” between looking straight up to looking straight down and vice versa.
I was wondering if there’s a way I can change this behavior so players can look up / down at 90 degrees. Thanks!
I have a hunch that this is caused by the LookVector of the camera when looking directly upwards being Vector3.new(0, 1, 0). The Y component is removed at some point, and the vector is again normalised - equivalent to Vector3.new(0, 0, 0).Unit, which evaluates to NAN, NAN, NAN, causing some unintended behaviour.
Looked at the newest version of the camera scripts just now - apparently, it is due to CFrame:lookAt(), though I’m still not sure how other people were able to get 90 degree camera angles, or more than 90 degree camera angles. Most likely wrote their own camera system.
I’m not familiar with that method - you mean CFrame.new(position, lookAt)? If so, that’s probably caused by passing a vector of NAN components as the second argument as I mentioned. The custom camera script that I’ve created doesn’t use this constructor and doesn’t experience the issue. You’re probably right.
Well, here’s a snippet of the current camera code, I haven’t touched it.
local newPos = cameraFocusP - vecToSubject
local desiredLookDir = camera.CFrame.lookVector
if self.rotateInput.x ~= 0 then
desiredLookDir = vecToSubject
end
local lookAt = Vector3.new(newPos.x + desiredLookDir.x, newPos.y, newPos.z + desiredLookDir.z)
And then the commented line, in the BaseCamera module script:
-- Note: DotProduct check in CoordinateFrame::lookAt() prevents using values within about
-- 8.11 degrees of the +/- Y axis, that's why these limits are currently 80 degrees
local MIN_Y = math.rad(-80)
local MAX_Y = math.rad(80)
This could potentially be an engine bug, or it’s something that can be fixed by developers.
Sorry for opening this back up so late, but I found a solution. The default roblox scripts all translate mouse movement, into modifying the position of the lookvector. Then it updates the camera by pointing it in the direction of the new lookvector.
If you use roblox’s default unaltered system, or even a system of your own in which you do the same method, you will never be able to get the camera to point straight down/up. I’m not sure the math behind that, but I’ve thoroughly tested to get to that conclusion.
The solution, is to make a custom system, or modify roblox’s to change the method of rotating the camera to angle modification instead. So instead of modifying the lookvector with mouse movement, you directly apply the input delta as *CFrame.Angles(). I’ve used this to create a seamless camera capable of doing smooth rolls and vertical loops. Without a roll correction function, eventually your rotation will naturally drift in a non-upright orientation. So keep that in mind.
What if you would use 89 degrees instead? Or a number really close to 90 degrees but isn’t exactly 90 degrees?
Just an example, what if you used 89.99 degrees instead?
Hope that helps, not sure if that’s exactly what you want but you could give it a try.