Sub topic 11
Positioning and aiming the camera
This chapter assumes you can orbit, pan, and zoom the 3D viewport, and that you know the camera object from earlier chapters. It also assumes you understand how focal length and sensor size set the field of view. The Python examples need only basic reading skills.
A camera has two spatial properties that decide the framing: where it is (location) and which way it faces (rotation). Focal length decides how much of the scene fits. Position and aim decide which part of the scene you see.
How a camera is oriented
A camera with all rotations at zero looks down its own -Z axis, and its +Y axis points to the top of the frame. This is why a new camera at rotation (0, 0, 0) looks straight down at the floor. Every aiming method below ends up setting this orientation, either directly or through a constraint.
Because the camera looks along -Z, you will see this pair of settings in the Track To constraint and in Python: track axis -Z, up axis Y.
Four ways to aim a camera
You can aim a camera by hand, with the viewport, with a constraint, or with code. The right choice depends on whether the subject moves and whether you want to keep editing the shot.
Align the camera to the viewport
This is the fastest way to frame a still shot. Orbit the viewport until you like the composition, then use View > Align View > Align Active Camera to View (Ctrl+Alt+Numpad 0). The active camera jumps to your viewport position and rotation.
The camera must already be the active scene camera, as described in the earlier chapter on the active camera. Otherwise you will move a different camera than the one you expect.
Lock Camera to View
Open camera view with Numpad 0, then open the N sidebar, go to the View tab, and enable Camera to View under View Lock. Now orbiting, panning, and zooming move the camera itself, so you frame the shot while looking through it.
This method has one hazard. While Camera to View is on, ordinary navigation edits the camera. If you leave it on and later orbit to inspect the scene, you will silently ruin the framing. Turn it off when you finish. Ctrl+Z recovers the old position only if you notice quickly.
Track To constraint
A Track To constraint rotates the camera so it always faces a target object. You move the camera freely, and the aim follows. This suits moving subjects and shots where you want to adjust position without re-aiming.
In the UI, select the camera, open the Object Constraint properties, and add Track To. Pick the target. For cameras the track axis should be -Z and the up axis Y. Recent Blender versions use these values when you add the constraint from the UI, but check them, because a wrong pair gives a camera that looks sideways or rolls.
import bpy
cam_obj = bpy.data.objects["ShotCamera"]
target = bpy.data.objects["Subject"]
con = cam_obj.constraints.new(type='TRACK_TO')
con.target = target
con.track_axis = 'TRACK_NEGATIVE_Z'
con.up_axis = 'UP_Y'Set both axes explicitly in scripts. Do not rely on the defaults of a constraint created through the API, which are not the camera-friendly pair.
The constraint overrides the camera's own rotation values. If you type a rotation and nothing changes, check the constraints tab first.
Aim at an Empty
The target of a Track To does not have to be the subject. Add an Empty (a point with no geometry) and aim at that instead. You can place the empty at a character's face rather than at the object origin, which is often at the feet. You can also parent the empty to the subject so it follows along.
An empty is also useful as a focus object for depth of field, covered in a later chapter. One empty can serve both purposes.
Computing a look-at rotation in Python
If you want a fixed rotation instead of a constraint, compute it from the direction between the camera and the point you want to see. Mathutils provides to_track_quat for this.
import bpy
from mathutils import Vector
scene = bpy.context.scene
cam_data = bpy.data.cameras.new("ShotCamera")
cam_obj = bpy.data.objects.new("ShotCamera", cam_data)
scene.collection.objects.link(cam_obj)
cam_obj.location = (7.0, -7.0, 5.0)
look_at = Vector((0.0, 0.0, 1.0))
direction = look_at - cam_obj.location
# The camera looks along -Z and keeps +Y as up.
rot_quat = direction.to_track_quat('-Z', 'Y')
cam_obj.rotation_euler = rot_quat.to_euler()
scene.camera = cam_objThe result is a plain rotation, not a live link. If the subject moves later, the camera will not follow. Use this when the subject is static and you want no constraint in the way, for example when generating many camera angles in a loop.
Choosing a position
Position controls three things: distance, height, and horizontal angle.
- Distance works together with focal length. The same subject size on screen can come from a close camera with a wide lens or a distant camera with a long lens. The two images differ in perspective, as the earlier chapter on wide and telephoto looks explained.
- Height sets the mood. A camera at eye level feels neutral. A low camera looking up makes a subject feel large. A high camera looking down makes it feel small.
- Horizontal angle decides which side of the subject you show. A three-quarter view, roughly 30 to 45 degrees off the front, usually shows form better than a flat front view.
Dolly versus zoom
Moving the camera and changing the focal length both change how big the subject looks, but they are different operations.
| Action | What changes | Perspective effect |
|---|---|---|
| Dolly (move camera closer or farther) | Camera location | Relative sizes of near and far objects change |
| Zoom (change focal length) | Field of view | Relative sizes stay the same, you only crop |
If you want a stronger sense of depth, move the camera closer and lower the focal length. If you want a flatter, compressed look, move it back and raise the focal length.
Orbiting around a subject
A common setup is a camera that circles the subject. Parent the camera to an Empty placed at the subject, then rotate the empty. The camera swings around on an arc, and a Track To constraint on the camera keeps it facing the subject.
import math
import bpy
scene = bpy.context.scene
subject = bpy.data.objects["Subject"]
cam_obj = bpy.data.objects["ShotCamera"]
rig = bpy.data.objects.new("CameraRig", None) # an Empty
scene.collection.objects.link(rig)
rig.location = subject.location
cam_obj.parent = rig
cam_obj.matrix_parent_inverse = rig.matrix_world.inverted()
rig.rotation_euler.z = math.radians(30)The matrix_parent_inverse line keeps the camera where it is when you parent it. Without it, the camera jumps because its location is reinterpreted relative to the empty. To animate the orbit, insert keyframes on the empty's Z rotation at two frames with rig.keyframe_insert(data_path="rotation_euler", index=2, frame=1) and again at the end frame after changing the value.
Common errors
- The camera looks at the floor or sideways. The track and up axes on a Track To constraint are wrong. Use -Z and Y.
- Typed rotation values have no effect. A constraint is overriding them. Disable or remove it.
- The image tilts. The camera has a roll. With a constraint, make sure the up axis is Y. With a manual rotation, set the Y rotation to zero.
- Align Active Camera to View moved the wrong camera. The scene has more than one camera, and the active one is not the one you meant to edit.
- The framing changed after you inspected the scene. Camera to View was still enabled.
- The subject is off-center even with Track To. The target's origin is not where you think. Aim at an empty placed on the point of interest.
Exercise
A camera is placed at (0, -10, 2) and must face the origin with the top of the frame pointing up. Which track axis and up axis does a Track To constraint need, and why does the camera need a different pair than a light might?
Show answer
Use track axis -Z and up axis Y. A camera looks down its local -Z axis and treats +Y as the top of the image, so the constraint must point -Z at the target while keeping +Y upward. Other objects, such as some lights, use different local axes for their direction, so the pair is a property of the object type, not a general rule.
Exercise
You parent a camera to an Empty in a script, and the camera jumps away from its original position. Which line was missing, and what does it do?
Show answer
Setting cam_obj.matrix_parent_inverse = rig.matrix_world.inverted() was missing. It stores the inverse of the parent's transform, so the camera's existing world position is preserved instead of being treated as an offset from the empty.