Camera Follow
BulletLab's CameraFollow keeps the PyBullet 3D camera locked on a moving
robot with a single update() call per step. Three modes are available.
Quickstart
from bulletlab import Simulation, Robot, CameraFollow
sim = Simulation(mode="gui").start()
robot = Robot.load("husky/husky.urdf", sim=sim, position=(0, 0, 0.3))
cam = CameraFollow(robot, sim) # defaults: smooth mode, 4 m back
while sim.is_connected:
sim.step()
cam.update() # ← one call per step
Modes
| Mode | Constant | Behaviour |
|---|---|---|
| Snap | "snap" |
Camera target locks to the robot instantly every frame |
| Smooth | "smooth" |
Camera target glides toward the robot (lerp). Cinematic feel |
| Chase | "chase" |
Camera yaw rotates with the robot's heading — always behind it |
# Snap – no lag
cam = CameraFollow(robot, sim, mode="snap")
# Smooth – gliding (default)
cam = CameraFollow(robot, sim, mode="smooth", lerp=0.08)
# Chase – 3rd-person, always behind the robot
cam = CameraFollow(robot, sim, mode="chase", distance=5.0, pitch=-20)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
robot |
Robot |
required | Robot to follow |
sim |
Simulation |
required | Simulation instance |
mode |
str |
"smooth" |
"snap", "smooth", or "chase" |
distance |
float |
4.0 |
Camera distance from robot (metres) |
pitch |
float |
-25.0 |
Vertical camera angle (degrees, negative = looking down) |
yaw |
float |
45.0 |
Horizontal angle (snap/smooth only, degrees) |
lerp |
float |
0.08 |
Smooth/chase glide speed (0 = frozen, 1 = instant) |
height_offset |
float |
0.2 |
Extra height above robot base (metres) |
Runtime Control
All parameters are writable at any time — change mode or settings on the fly:
cam.mode = "chase" # switch mode mid-run
cam.distance = 6.0 # zoom out
cam.pitch = -35.0 # look more steeply down
cam.lerp = 0.15 # glide faster
API Reference
Robot-tracking camera controller.
Wraps sim.set_camera() and updates the PyBullet debug camera every
time :meth:update is called — typically once per simulation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
'Robot'
|
The robot to follow. |
required |
sim
|
'Simulation'
|
The :class: |
required |
mode
|
str
|
Tracking mode – |
'smooth'
|
distance
|
float
|
Camera distance from the robot in metres. Default |
4.0
|
pitch
|
float
|
Camera pitch angle in degrees (negative = looking down).
Default |
-25.0
|
yaw
|
float
|
Initial yaw angle in degrees. Only used in |
45.0
|
lerp
|
float
|
Lerp factor used in |
0.08
|
height_offset
|
float
|
Extra height added to the camera target above the
robot's base position (metres). Default |
0.2
|
Modes
"snap"– target snaps to the robot instantly each step."smooth"– target slides toward the robot using lerp."chase"– camera yaw tracks the robot's heading so the camera always looks at the robot from behind.
Example::
from bulletlab import Simulation, Robot
from bulletlab.core.camera import CameraFollow
sim = Simulation(mode="gui").start()
robot = Robot.load("husky/husky.urdf", sim=sim)
# One-liner: camera that smoothly follows the robot
cam = CameraFollow(robot, sim, mode="smooth")
while sim.is_connected:
sim.step()
cam.update()
Source code in bulletlab/core/camera.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
distance: float
property
writable
Camera distance from the robot in metres.
enabled: bool
property
writable
Whether the camera follow is active.
Set to False to freeze the camera at its current position.
Set to True to resume tracking.
Example::
cam.enabled = False # freeze
cam.enabled = True # resume
lerp: float
property
writable
Lerp factor used in smooth mode (0 < lerp ≤ 1).
mode: str
property
writable
Current tracking mode ("snap", "smooth", or "chase").
pitch: float
property
writable
Camera pitch in degrees.
yaw: float
property
writable
Camera yaw in degrees (snap/smooth modes only).
update() -> None
Update the camera for the current simulation frame.
Call once per simulation step in your main loop. When
:attr:enabled is False the call is a no-op and the camera
stays fixed at its last position.
Example::
while sim.is_connected:
sim.step()
cam.update()