Camera Controller
A modular and customizable system for managing camera behavior. This component includes multiple presets such as third-person, follow, orbit, and gyroscope modes, allowing developers to fine-tune camera positioning, movement, and responsiveness for a wide range of gaming experiences and interactive Lens formats.
Key Features
The Camera Controller component provides four distinct camera behaviors:
- Follow Mode - Camera tracks a target object's position with optional axis locking
- Third-Person Mode - Automatically follows a character and rotates toward character direction
- Orbit Mode - Allows free rotation around a target with touch controls
- Gyroscope Mode - Uses device orientation to rotate the camera around a pivot relative to the target
Usage
- Locate the Camera Controller custom component in the Asset Library.
- Click the
Installbutton to add it to your project. Once installed, the component can be attached to a Scene Object. - Set the Camera Input to the Camera Object you want to control and select the
Camera Modeyou wish to use. - Set the
Follow Targetto the Scene Object you want the Camera to track. - Customize the camera behavior by adjusting the
Smoothing Factor,OffsetandLock Axissettings.
Camera Modes
Follow Mode
The camera tracks the Follow Target's position while maintaining its current orientation. Ideal for side-scrolling games or situations where you want the camera to move but not rotate.
Features:
- Tracks target position only
- Maintains camera's original rotation
- Supports axis locking for 2D-style movement
- Configurable smoothing for natural movement
Third Person Mode
Automatically follows a character and rotates toward the character's direction. Perfect for third-person adventure games, character showcases, and exploration experiences.
Features:
- Follows target position and rotation
- Maintains consistent distance from target
- Smooth interpolation for natural camera movement
- Works seamlessly with
Character Controllercomponent
Usage with Character Controller:
To use Third Person Mode with a character, attach the Camera Controller component to your camera and set the
Follow Target to the Scene Object that has the Character Controller component attached. The camera will
automatically follow the character's movement and rotate to face the direction the character is moving.
Camera Placement: When using Third Person Mode, make sure to position your camera behind the character in the scene. The camera will maintain this relative position and distance as it follows the character.
Orbit Mode
Allows free rotation around a target using touch controls. Users can tap and drag within a specified Interactive Area
to orbit the camera around the Follow Target, ideal for interactive 3D object viewers and third person games.
Features:
- Touch-controlled camera rotation
- Configurable interaction area
- Automatic orbit option for hands-free rotation
- Vertical and horizontal rotation clamping
- Adjustable orbit speed
Gyroscope Mode
Uses the device's orientation to rotate the camera around a pivot positioned relative to the Follow Target. Ideal for
device-tilt controls, first/third-person exploration, and immersive object/viewer experiences.
Features:
- Device-orientation-driven camera rotation (roll, pitch, yaw)
- Selectable active axes: Roll, Pitch, Yaw
- Calibration helpers
- Use
calibrateToCurrentDevice()to set the current device orientation as the zero reference. - Or call
calibrateYaw(),calibratePitch(), orcalibrateRoll()to adjust specific axes during gameplay.
Camera Mode Selection:
- Use Follow for side-scrolling or platform games
- Use Third Person for character-based adventure games
- Use Orbit for interactive 3D showcases and object viewers
- Use Gyroscope for device-tilt driven interactions and immersive exploration
Obstacle Avoidance
Camera Controller includes built-in obstacle avoidance to make sure the camera has a clear line of sight to the Follow Target. If an obstacle is detected between the camera and the target, the camera will adjust its position to move closer to the target, preventing clipping through objects.
Character Collider: Make sure to add your Character Controller to the Character To Ignore input of the Camera Controller to prevent the camera from colliding with the character itself.
Obstacle avoidance uses raycasting to detect obstacles.
Make sure that the objects you want the camera to avoid have appropriate colliders (Physics Collider or Physics Body, non-intangible).
Add any collider you want the camera to ignore to the Colliders To Ignore array in the Camera Controller component.
You can debug obstacle avoidance by checking the Enable Debug option in Obstacle Avoidance section of the Camera Controller component.
This example shows the raycast used for obstacle detection (using a different camera for clarity):
Component Inputs
| Name | Type | Description |
|---|---|---|
| Camera | SceneObject or null | The camera object this script will control. |
| Follow Target | SceneObject or null | Scene Object that the camera will track / follow. |
| Snap To Target On Awake | boolean | If enabled, the camera will immediately snap to the target location when the CameraController awakens. |
| Camera Mode | string | Initial camera mode. One of "Orbit", "Third Person", "Follow", "Gyroscope". |
| Print Warning Logs | boolean | If true, warning logs will be printed. |
| Print Info Logs | boolean | If true, info logs will be printed. |
| Orbit Mode | ||
| Smoothing Factor | number | Controls how smoothly the camera follows its target (higher = smoother), min 0 – max 1. |
| Radius | number | Distance from target to camera. |
| Pivot Offset | vec3 | Offset relative to the Follow Target's transform that positions the orbit pivot (the point the camera orbits around) in the target's local space. |
| Orbit Speed | number | Controls how fast the camera rotates around the target. The sign of the speed defines the direction of auto-orbit movement. |
| Auto Orbit | boolean | If enabled, the camera will continuously orbit around the target. |
| Vertical Clamp | vec3 | Limits how far up/down the camera can rotate. Format: (min, max, default). |
| Horizontal Clamp | vec3 | Limits how far left/right the camera can rotate. Format: (min, max, default). |
| Interactive Area | InteractionComponent | Touchable screen region for swipe/gesture control. If null, the whole screen is interactive. |
| Third Person Mode | ||
| Smoothing Factor | number | Controls how smoothly the camera follows its target (higher = smoother), min 0 – max 1. |
| Use Scene Derived Offset | boolean | If enabled, automatically derives the camera's relative position & rotation offset from the current scene setup. |
| Position Offset | vec3 | Position offset from target. Applicable if Use Scene Derived Offset is disabled. |
| Rotation Offset | vec3 | Additional rotation offset. Applicable if Use Scene Derived Offset is disabled. |
| Follow Mode | ||
| Smoothing Factor | number | Controls how smoothly the camera follows its target (higher = smoother), min 0 – max 1. |
| Use Scene Derived Offset | boolean | If enabled, automatically derives the camera's relative position offset from the current scene setup. |
| Position Offset | vec3 | Offset from target. Applicable if Use Scene Derived Offset is disabled. |
| Lock X | boolean | Restricts the camera from moving or rotating along the X axis. |
| Lock Y | boolean | Restricts the camera from moving or rotating along the Y axis. |
| Lock Z | boolean | Restricts the camera from moving or rotating along the Z axis. |
| Gyroscope Mode | ||
| Smoothing Factor | number | Controls smoothing of the pivot/position movement (higher = smoother). Does not smooth device rotation. Min 0 – max 1. |
| Pivot Position | vec3 | Offset relative to the target transform used to place the rotation pivot. |
| Pivot Rotation | vec3 | Extra Euler rotation (degrees) applied at the pivot before device rotation. |
| Position Offset | vec3 | Camera position offset from the pivot, applied after pivot and device rotation. |
| Active Axes | enum | Which device axes affect camera rotation. One of: All, Roll, Pitch, Yaw, RollPitch, RollYaw, PitchYaw. |
| Obstacle Avoidance | ||
| Avoid Obstacles | boolean | If enabled, the camera will avoid obstacles between itself and the Follow Target. |
| Check Radius | number | Radius of the raycast sphere used during obstacle avoidance checks (higher = larger area checked for obstacles) |
| Origin Offset | vec3 | Offset relative to the target transform (position, scale, rotation) to start the raycast from |
| Character To Ignore | ScriptComponent | The Character Controller to ignore its collider during obstacle avoidance checks |
| Colliders To Ignore | ColliderComponent[] | Additional colliders to ignore during obstacle avoidance checks |
| Return Smoothing Factor | number | Controls how quickly the camera moves back to its desired position after avoiding an obstacle (higher = faster), min value - 0, max value - 1 |
| Minimum Distance Factor | number | Minimum distance to maintain from the target when avoiding obstacles (higher = further away), min value - 0, max value - 1 |
| Enable Debug | boolean | Enables debug drawing of the obstacle avoidance raycast checks |
Component API
| Name (signature) | Description |
|---|---|
camera: SceneObject | null | Gets/sets the SceneObject the component drives. |
followTarget: SceneObject | null | Gets/sets the SceneObject the camera follows. |
cameraMode: CameraMode | Returns the currently active camera mode. |
enableFollowCameraMode(): FollowCameraModeStrategy | Switches the component to Follow mode and returns the strategy object for runtime modifications. |
enableThirdPersonCameraMode(): ThirdPersonCameraModeStrategy | Switches the component to Third Person mode and returns the strategy object for runtime modifications. |
enableOrbitCameraMode(): OrbitCameraModeStrategy | Switches the component to Orbit mode and returns the strategy object for runtime modifications. |
enableGyroscopeCameraMode(): GyroscopeCameraModeStrategy | Switches the component to Gyroscope mode and returns the strategy object for runtime modifications. |
getCameraModeStrategy(): CameraModeStrategy | null | Gets the currently active camera mode strategy object. You can cast this to a specific type (e.g., OrbitCameraModeStrategy) to modify it. |
moveToTarget(): void | Instantly moves the camera to its final position (without smoothing). It is useful after switching modes. |
getObstacleAvoidance(): ObstacleAvoidance | Returns the current ObstacleAvoidance instance, which can be used to tweak obstacle avoidance settings. |
setObstacleAvoidance(obstacleAvoidance: ObstacleAvoidance): void | Sets a new ObstacleAvoidance instance. |
isObstacleAvoidanceEnabled(): boolean | Returns true if obstacle avoidance is enabled |
enableObstacleAvoidance(): void | Enables obstacle avoidance by moving the camera closer to the target when obstacles are detected. |
disableObstacleAvoidance(): void | Disables obstacle avoidance. The camera will not adjust its position when obstacles are detected. |
printWarningLogs: boolean | Gets/sets the flag for printing warning logs. |
printInfoLogs: boolean | Gets/sets the flag for printing info logs. |
Mode-specific API
The enable...CameraMode() methods return a strategy object when a mode is activated. You can also get the currently
active strategy object at any time by calling getCameraModeStrategy(). This object allows you to modify the mode's
properties at runtime.
Follow Mode (FollowCameraModeStrategy)
| Name | Type | Description |
|---|---|---|
smoothingFactor | number | Controls how smoothly the camera follows its target (0-1, higher = smoother). |
positionOffset | vec3 | Local-space offset applied to the camera position. |
lockX | boolean | Restricts the camera from moving / rotating along world X axis. |
lockY | boolean | Restricts the camera from moving / rotating along world Y axis. |
lockZ | boolean | Restricts the camera from moving / rotating along world Z axis. |
Third Person Mode (ThirdPersonCameraModeStrategy)
| Name | Type | Description |
|---|---|---|
smoothingFactor | number | Controls how smoothly the camera follows its target (0-1, higher = smoother). |
positionOffset | vec3 | Local-space offset applied to the camera position. |
rotationOffset | quat | Additional rotation applied to the camera as a quaternion. |
Orbit Mode (OrbitCameraModeStrategy)
| Name | Type | Description |
|---|---|---|
smoothingFactor | number | Controls how smoothly the camera follows its target (0-1, higher = smoother). |
radius | number | Distance from target to camera. |
pivotOffset | vec3 | Offset relative to the Follow Target's transform that positions the orbit pivot in the target's local space. |
orbitSpeed | number | Controls how fast the camera orbits around the target. |
autoOrbit | boolean | If enabled, the camera will continuously orbit around the target. |
verticalClamp | vec3 | Limits how far up/down the camera can rotate. Format: (min, max, default). |
horizontalClamp | vec3 | Limits how far left/right the camera can rotate. Format: (min, max, default). |
interactiveArea | InteractionComponent | Touchable screen region for swipe / gesture-based control. |
Gyroscope Mode (GyroscopeCameraModeStrategy)
Properties
| Name | Type | Description |
|---|---|---|
smoothingFactor | number | Controls pivot/position smoothing applied to target. Does not smooth device rotation. |
pivotPosition | vec3 | Pivot offset relative to the target. |
pivotRotation | quat | Additional pivot rotation. In the inspector you can enter Euler degrees; at runtime it's a quaternion. |
positionOffset | vec3 | Camera offset applied after pivot and device rotation. |
activeAxes | enum | Which device axes are applied to rotation. One of: All, Roll, Pitch, Yaw, RollPitch, RollYaw, PitchYaw. |
zeroRotation | quat | Calibration reference treated as identity. Incoming device rotation R is calibrated as Z^-1 · R (Z is zeroRotation), then filtered by activeAxes. Not smoothed. |
Methods
| Signature | Description |
|---|---|
calibrateToCurrentDevice(): void | Set current device orientation as zero. |
calibrateYaw(): void | Calibrate yaw only. |
calibratePitch(): void | Calibrate pitch only. |
calibrateRoll(): void | Calibrate roll only. |
Obstacle Avoidance API
Obstacle avoidance can be configured at runtime using the ObstacleAvoidance instance returned by calling getObstacleAvoidance().
| Name (signature) | Description |
|---|---|
calculatePosition(targetTransform: Transform, desiredCameraPosition: vec3): vec3 | Calculates a new camera position to avoid obstacles between the target and desired camera position. Returns the adjusted camera position. |
getCheckRadius(): number | Returns the radius used for the RayCast obstacle checks. |
setCheckRadius(radius: number): void | Sets the new radius for the RayCast obstacle checks. |
getOriginOffset(): vec3 | Returns the offset from the target used as the origin for the RayCast obstacle checks. Relative to the target's transform. |
setOriginOffset(offset: vec3): void | Sets the new offset from the target for the RayCast obstacle checks. Relative to the target's transform. |
getCharacterToIgnore(): ScriptComponent | null | Returns the Character Controller script to ignore during obstacle checks or null if none is set. |
setCharacterToIgnore(character: ScriptComponent | null): void | Sets the Character Controller script to ignore during obstacle checks or null to clear the current setting. |
getCollidersToIgnore(): ColliderComponent[] | Returns the colliders to ignore during obstacle checks. |
setCollidersToIgnore(colliders: ColliderComponent[]): void | Sets the colliders to ignore during obstacle checks. |
getReturnSmoothingFactor(): number | Returns the smoothing factor for returning the camera to the desired position if obstacles are no longer detected. |
setReturnSmoothingFactor(factor: number): void | Sets the new smoothing factor for returning the camera to the desired position if obstacles are no longer detected. |
getMinDistanceFactor(): number | Returns the minimum distance factor from the target when avoiding obstacles. 0 means the camera can be at the target position, 1 means the camera cannot move from its desired position. |
setMinDistanceFactor(factor: number): void | Sets the new minimum distance factor from the target when avoiding obstacles. 0 means the camera can be at the target position, 1 means the camera cannot move from its desired position. |
enableDebug(): void | Enable debug mode for showing the RayCast probe in the scene. |
disableDebug(): void | Disable debug mode for hiding the RayCast probe in the scene. |
Testing on Device
To preview your Lens in Snapchat, follow the Pairing to Snapchat guide.