Camera not angling

camera.CFrame = CFrame.new(target.Position) * CFrame.Angles(0, math.rad(90), 0) * CFrame.new(0, 0, -10)

camera.CFrame = CFrame.new(target.Position) * CFrame.Angles(0, math.rad(90), math.rad(90)) * CFrame.new(0, 0, -10)

I can’t seem to get the camera to face down. The Z axis should be what makes the camera face down, but when I do math.rad(90) it just rotates the camera on the X axis. Exact same thing happens when I have this:

camera.CFrame = CFrame.new(target.Position) * CFrame.Angles(math.rad(90), math.rad(90), 0) * CFrame.new(0, 0, -10)

I’m pretty sure it’s the X axis, no?

camera.CFrame = CFrame.new(target.Position+Vector3.new(0,10,0))*CFrame.Angles(math.rad(-90),0,0)
1 Like

Still doesn’t tilt the camera down, just rotates it.

Z axis runs forwards and backwards. Rotating the camera on the Z will roll the camera, rather than tilt. You do want the X axis, as Dragon mentioned. If worse comes to worse, you could also use this to point the camera straight down.

canera.CFrame = CFrame.new(target.Position + Vector3.new(0,10,0), target.Position)

1 Like

Well that’s what I want, I want the camera facing down

Bump

To point the camera directly down, you can set it thus:

game.Workspace.CurrentCamera.CFrame = CFrame.fromOrientation(-0.5*math.pi, y, 0) + game.Workspace.CurrentCamera.CFrame.p

Where y is an angle from 0 to 2*math.pi, depending on how you want the camera upVector pointed (0 will point it in the -Z direction). If the camera’s lookVector is already in the X-Z plane (i.e. camera level with the ground plane), only then will a 90-degree X-axis rotation point it straight down. But since you know the desired orientation explicitly, it makes more sense to just assign it.

The camera should be set to type Scriptable, of course.

Due to how the CFrame.new(Vector3,Vector3) internally tries to pick a CFrame with a world Y-axis “up”, I don’t recommend using this constructor to generate CFrames within about 8 degrees of looking directly up or down, as you can get unexpected, arbitrary orientation for the unspecified axis (in this case, what ends up as the camera’s upVector direction).

1 Like

camera.CFrame = CFrame.new(target.Position) * CFrame.Angles(0, angle, 0) * CFrame.new(0, 0, -10)

This is part of my original code. The ‘angle’ is a math.rad that goes up by 10 in a loop until it reaches 90. What I want is to also rotate the camera to face down at the same time. But I’ve put math.rad’s in both the X and Z spots in CFrame.Angles but none of them rotate the camera to face down which I can’t understand. The X and Z spots basically put the camera in the same position as each, like they are on the same plane or something.

You don’t need to keep bumping your thread, what you ought to do is explain what you need more clearly because we’ve provided code for the camera behavior you’ve described. Either something in your camera is broken and not using the code as it should be or you’re describing different behavior. It would really help to have a diagram or example of sorts, plus some screenshots if possible.

X and Z axis rotations doing the same thing suggests that you’re applying rotations in the wrong order and getting gimbal lock. There are a few different CFrame functions that return a CFrame from angles, and they do the rotations in specific orders. CFrame.Angles uses XYZ order like CFrame.fromEulerAnglesXYZ, but your problem suggests you are expecting YXZ order which requires either using CFrame.fromOrientation() as I suggested above, or CFrame.fromEulerAnglesYXZ() which does the same. You can use CFrame.Angles, but you have to make two calls to it with just the Y rotation non-zero in one and the X or Z rotation in the other, and then multiply them in the correct order, i.e.:

CFrame.new(pos) * CFrame.Angles(0, yAngle, 0) * CFrame.Angles(xAngle, 0, 0)

which is the same as the more efficient:

CFrame.new(pos) * CFrame.fromOrientation(xAngle,yAngle,0)

If you use the CFrame.Angles constructor and order the multiplication wrong, you’ll still have your unexpected behavior. With XYZ order, you do the X rotation, then Y then Z, so if your Y axis rotation is, say, 90 degrees, local-coordinate space X and Z axis rotations can end up being around the exact same axis in world space (i.e. the Y rotation rotates the Z axis to where the X axis was when it’s rotation was applied).

4 Likes