Skip to main content
Version: 5.x
Supported on
Snapchat
Camera Kit

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:

  1. Follow Mode - Camera tracks a target object's position with optional axis locking
  2. Third-Person Mode - Automatically follows a character and rotates toward character direction
  3. Orbit Mode - Allows free rotation around a target with touch controls
  4. Gyroscope Mode - Uses device orientation to rotate the camera around a pivot relative to the target

Usage

  1. Locate the Camera Controller custom component in the Asset Library.
  2. Click the Install button to add it to your project. Once installed, the component can be attached to a Scene Object.
  3. Set the Camera Input to the Camera Object you want to control and select the Camera Mode you wish to use.
  4. Set the Follow Target to the Scene Object you want the Camera to track.
  5. Customize the camera behavior by adjusting the Smoothing Factor, Offset and Lock Axis settings.

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 Controller component

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(), or calibrateRoll() 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

NameTypeDescription
CameraSceneObject or nullThe camera object this script will control.
Follow TargetSceneObject or nullScene Object that the camera will track / follow.
Snap To Target On AwakebooleanIf enabled, the camera will immediately snap to the target location when the CameraController awakens.
Camera ModestringInitial camera mode. One of "Orbit", "Third Person", "Follow", "Gyroscope".
Print Warning LogsbooleanIf true, warning logs will be printed.
Print Info LogsbooleanIf true, info logs will be printed.
Orbit Mode
Smoothing FactornumberControls how smoothly the camera follows its target (higher = smoother), min 0 – max 1.
RadiusnumberDistance from target to camera.
Pivot Offsetvec3Offset 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 SpeednumberControls how fast the camera rotates around the target. The sign of the speed defines the direction of auto-orbit movement.
Auto OrbitbooleanIf enabled, the camera will continuously orbit around the target.
Vertical Clampvec3Limits how far up/down the camera can rotate. Format: (min, max, default).
Horizontal Clampvec3Limits how far left/right the camera can rotate. Format: (min, max, default).
Interactive AreaInteractionComponentTouchable screen region for swipe/gesture control. If null, the whole screen is interactive.
Third Person Mode
Smoothing FactornumberControls how smoothly the camera follows its target (higher = smoother), min 0 – max 1.
Use Scene Derived OffsetbooleanIf enabled, automatically derives the camera's relative position & rotation offset from the current scene setup.
Position Offsetvec3Position offset from target. Applicable if Use Scene Derived Offset is disabled.
Rotation Offsetvec3Additional rotation offset. Applicable if Use Scene Derived Offset is disabled.
Follow Mode
Smoothing FactornumberControls how smoothly the camera follows its target (higher = smoother), min 0 – max 1.
Use Scene Derived OffsetbooleanIf enabled, automatically derives the camera's relative position offset from the current scene setup.
Position Offsetvec3Offset from target. Applicable if Use Scene Derived Offset is disabled.
Lock XbooleanRestricts the camera from moving or rotating along the X axis.
Lock YbooleanRestricts the camera from moving or rotating along the Y axis.
Lock ZbooleanRestricts the camera from moving or rotating along the Z axis.
Gyroscope Mode
Smoothing FactornumberControls smoothing of the pivot/position movement (higher = smoother). Does not smooth device rotation. Min 0 – max 1.
Pivot Positionvec3Offset relative to the target transform used to place the rotation pivot.
Pivot Rotationvec3Extra Euler rotation (degrees) applied at the pivot before device rotation.
Position Offsetvec3Camera position offset from the pivot, applied after pivot and device rotation.
Active AxesenumWhich device axes affect camera rotation. One of: All, Roll, Pitch, Yaw, RollPitch, RollYaw, PitchYaw.
Obstacle Avoidance
Avoid ObstaclesbooleanIf enabled, the camera will avoid obstacles between itself and the Follow Target.
Check RadiusnumberRadius of the raycast sphere used during obstacle avoidance checks (higher = larger area checked for obstacles)
Origin Offsetvec3Offset relative to the target transform (position, scale, rotation) to start the raycast from
Character To IgnoreScriptComponentThe Character Controller to ignore its collider during obstacle avoidance checks
Colliders To IgnoreColliderComponent[]Additional colliders to ignore during obstacle avoidance checks
Return Smoothing FactornumberControls how quickly the camera moves back to its desired position after avoiding an obstacle (higher = faster), min value - 0, max value - 1
Minimum Distance FactornumberMinimum distance to maintain from the target when avoiding obstacles (higher = further away), min value - 0, max value - 1
Enable DebugbooleanEnables debug drawing of the obstacle avoidance raycast checks

Component API

Name (signature)Description
camera: SceneObject | nullGets/sets the SceneObject the component drives.
followTarget: SceneObject | nullGets/sets the SceneObject the camera follows.
cameraMode: CameraModeReturns the currently active camera mode.
enableFollowCameraMode(): FollowCameraModeStrategySwitches the component to Follow mode and returns the strategy object for runtime modifications.
enableThirdPersonCameraMode(): ThirdPersonCameraModeStrategySwitches the component to Third Person mode and returns the strategy object for runtime modifications.
enableOrbitCameraMode(): OrbitCameraModeStrategySwitches the component to Orbit mode and returns the strategy object for runtime modifications.
enableGyroscopeCameraMode(): GyroscopeCameraModeStrategySwitches the component to Gyroscope mode and returns the strategy object for runtime modifications.
getCameraModeStrategy(): CameraModeStrategy | nullGets the currently active camera mode strategy object. You can cast this to a specific type (e.g., OrbitCameraModeStrategy) to modify it.
moveToTarget(): voidInstantly moves the camera to its final position (without smoothing). It is useful after switching modes.
getObstacleAvoidance(): ObstacleAvoidanceReturns the current ObstacleAvoidance instance, which can be used to tweak obstacle avoidance settings.
setObstacleAvoidance(obstacleAvoidance: ObstacleAvoidance): voidSets a new ObstacleAvoidance instance.
isObstacleAvoidanceEnabled(): booleanReturns true if obstacle avoidance is enabled
enableObstacleAvoidance(): voidEnables obstacle avoidance by moving the camera closer to the target when obstacles are detected.
disableObstacleAvoidance(): voidDisables obstacle avoidance. The camera will not adjust its position when obstacles are detected.
printWarningLogs: booleanGets/sets the flag for printing warning logs.
printInfoLogs: booleanGets/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)

NameTypeDescription
smoothingFactornumberControls how smoothly the camera follows its target (0-1, higher = smoother).
positionOffsetvec3Local-space offset applied to the camera position.
lockXbooleanRestricts the camera from moving / rotating along world X axis.
lockYbooleanRestricts the camera from moving / rotating along world Y axis.
lockZbooleanRestricts the camera from moving / rotating along world Z axis.

Third Person Mode (ThirdPersonCameraModeStrategy)

NameTypeDescription
smoothingFactornumberControls how smoothly the camera follows its target (0-1, higher = smoother).
positionOffsetvec3Local-space offset applied to the camera position.
rotationOffsetquatAdditional rotation applied to the camera as a quaternion.

Orbit Mode (OrbitCameraModeStrategy)

NameTypeDescription
smoothingFactornumberControls how smoothly the camera follows its target (0-1, higher = smoother).
radiusnumberDistance from target to camera.
pivotOffsetvec3Offset relative to the Follow Target's transform that positions the orbit pivot in the target's local space.
orbitSpeednumberControls how fast the camera orbits around the target.
autoOrbitbooleanIf enabled, the camera will continuously orbit around the target.
verticalClampvec3Limits how far up/down the camera can rotate. Format: (min, max, default).
horizontalClampvec3Limits how far left/right the camera can rotate. Format: (min, max, default).
interactiveAreaInteractionComponentTouchable screen region for swipe / gesture-based control.

Gyroscope Mode (GyroscopeCameraModeStrategy)

Properties
NameTypeDescription
smoothingFactornumberControls pivot/position smoothing applied to target. Does not smooth device rotation.
pivotPositionvec3Pivot offset relative to the target.
pivotRotationquatAdditional pivot rotation. In the inspector you can enter Euler degrees; at runtime it's a quaternion.
positionOffsetvec3Camera offset applied after pivot and device rotation.
activeAxesenumWhich device axes are applied to rotation. One of: All, Roll, Pitch, Yaw, RollPitch, RollYaw, PitchYaw.
zeroRotationquatCalibration reference treated as identity. Incoming device rotation R is calibrated as Z^-1 · R (Z is zeroRotation), then filtered by activeAxes. Not smoothed.
Methods
SignatureDescription
calibrateToCurrentDevice(): voidSet current device orientation as zero.
calibrateYaw(): voidCalibrate yaw only.
calibratePitch(): voidCalibrate pitch only.
calibrateRoll(): voidCalibrate 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): vec3Calculates a new camera position to avoid obstacles between the target and desired camera position. Returns the adjusted camera position.
getCheckRadius(): numberReturns the radius used for the RayCast obstacle checks.
setCheckRadius(radius: number): voidSets the new radius for the RayCast obstacle checks.
getOriginOffset(): vec3Returns the offset from the target used as the origin for the RayCast obstacle checks. Relative to the target's transform.
setOriginOffset(offset: vec3): voidSets the new offset from the target for the RayCast obstacle checks. Relative to the target's transform.
getCharacterToIgnore(): ScriptComponent | nullReturns the Character Controller script to ignore during obstacle checks or null if none is set.
setCharacterToIgnore(character: ScriptComponent | null): voidSets 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[]): voidSets the colliders to ignore during obstacle checks.
getReturnSmoothingFactor(): numberReturns the smoothing factor for returning the camera to the desired position if obstacles are no longer detected.
setReturnSmoothingFactor(factor: number): voidSets the new smoothing factor for returning the camera to the desired position if obstacles are no longer detected.
getMinDistanceFactor(): numberReturns 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): voidSets 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(): voidEnable debug mode for showing the RayCast probe in the scene.
disableDebug(): voidDisable 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.

Was this page helpful?
Yes
No