githubEdit

Camera Controls (OrbitControls)

The core camera controller for interactive 3D experiences. Rotate, pan, and zoom around your scene with mouse, touch, and keyboard. Works in Unity and Blender.

The primary camera controller for navigating and exploring 3D scenes with intuitive mouse, touch, and keyboard controls.

:::tip Works with Unity and Blender The OrbitControls component is available for both Unity and Blender integrations. :::

What You Can Do

  • Rotate - Orbit around objects by dragging

  • Pan - Move the camera side-to-side (right-click drag or two-finger touch)

  • Zoom - Scroll to zoom in/out

  • Auto-Rotate - Automatically rotate the camera around the scene

  • Auto-Fit - Automatically frame the entire scene

  • Focus on Click - Double-click objects to focus on them

  • Smooth Animations - Animate camera movements programmatically

Perfect for:

  • Product showcases and configurators

  • Architectural visualizations

  • Interactive 3D models

  • Any scene requiring camera control

  • All Needle Engine projects (it's the default!)

Quick Start

Default Behavior

OrbitControls is typically added automatically to your camera in Unity or Blender. Just export and you're ready to go!

Controls:

  • Left-click drag - Rotate around the scene

  • Right-click drag or Two-finger touch - Pan the camera

  • Mouse wheel or Pinch - Zoom in/out

  • Double-click - Focus on the clicked object

Adding Manually

In Unity or Blender:

  1. Select your camera object

  2. Add the OrbitControls component

  3. Export - camera controls are now active!

Core Features

Auto-Rotate

Automatically rotate the camera for presentations:

In Editor:

  1. Enable Auto Rotate on the OrbitControls component

  2. Set Auto Rotate Speed (default is 1.0)

  3. The camera rotates automatically - any user interaction stops it

From Code:

Auto-Fit to Scene

Automatically frame the entire scene when it loads or when users click the background:

In Editor:

  • Enable Auto Fit - Camera frames all objects on start

  • Set Click Background To Fit Scene - Number of clicks on background to re-fit (default: 2)

Users can double-click the background at any time to re-fit the camera to the entire scene.

From Code:

Focus on Objects

Users can double-click objects to focus the camera on them. Configure this behavior:

Setting
What it does
Default

Double Click To Focus

Focus on object when double-clicked

true

Middle Click To Focus

Focus on object when middle-clicked

true

Click Background To Fit Scene

Number of clicks on background to fit entire scene

2

Settings

Rotation Controls

Setting
What it does
Default

Enable Rotate

Allow camera rotation

true

Auto Rotate

Automatically rotate camera

false

Auto Rotate Speed

Rotation speed when auto-rotating

1.0

Min Azimuth Angle

Minimum horizontal rotation (radians)

Infinity (no limit)

Max Azimuth Angle

Maximum horizontal rotation (radians)

Infinity (no limit)

Min Polar Angle

Minimum vertical rotation (radians)

0

Max Polar Angle

Maximum vertical rotation (radians)

Math.PI

Zoom Controls

Setting
What it does
Default

Enable Zoom

Allow zooming

true

Zoom Speed

How fast zooming happens

1

Zoom To Cursor

Zoom toward cursor position instead of center

false

Min Zoom

Minimum zoom distance

0

Max Zoom

Maximum zoom distance

Infinity

Pan Controls

Setting
What it does
Default

Enable Pan

Allow panning

true

Movement Feel

Setting
What it does
Default

Enable Damping

Smooth, inertial movement

true

Damping Factor

How much damping (lower = more smooth)

0.1

Enable Keys

Allow keyboard controls

false

Behavior

Setting
What it does
Default

Auto Target

Automatically find focus point

true

Auto Fit

Fit scene to view on start

false

Allow Interrupt

User input stops animations

true

Target Lerp Duration

Animation duration in seconds

1

Examples

Product Viewer

Create a product showcase that auto-rotates until touched:

Restrict Camera Movement

Limit rotation to prevent users from seeing under/behind objects:

Animate Camera to Position

Smoothly move camera to look at a specific object:

Fit Specific Objects

Frame specific objects instead of the whole scene:

Keyboard Controls

Enable keyboard navigation:

Scripting API

Camera Movement

Camera Animations

Field of View

Fitting Camera

Access Three.js Controls

Events

Advanced Features

Look At Constraints

Make the camera always look at a specific object:

In Editor:

  1. Create a LookAtConstraint component

  2. Assign the target object to the constraint

  3. Assign the constraint to Look At Constraint on OrbitControls

The camera will always look at the constrained object while users control it.

Target Bounds

Restrict where users can pan the camera:

In Editor:

  1. Create an empty object to define the bounds

  2. Scale it to the desired size

  3. Assign it to Target Bounds on OrbitControls

Users can only pan within this defined volume.

Custom Dom Element

Make OrbitControls listen to a different HTML element:

Common Questions

How do I disable camera controls temporarily? Disable the OrbitControls component: orbit.enabled = false;

Can users control the camera in VR/AR? OrbitControls automatically disables in XR mode. Camera control happens through the headset instead.

Why does auto-rotate stop when I interact? This is default behavior. Auto-rotation resumes only if you re-enable it via script.

How do I prevent users from seeing under the floor? Set Min Polar Angle and Max Polar Angle to limit vertical rotation.

Can I change controls sensitivity? Yes! Adjust Damping Factor (lower = smoother), Zoom Speed, and Auto Rotate Speed.

How do I focus camera on an object immediately? Use orbit.setCameraAndLookTarget(targetObject, true); - the true makes it instant.

Can I use keyboard controls? Enable Enable Keys to allow arrow key navigation.

Performance Tips

Damping: Damping creates smooth motion but requires updates every frame. For static presentations, you can disable it once camera settles.

Auto-Rotate: Auto-rotation updates every frame. Disable when not needed to save performance.

Manual Updates: For very static scenes, consider handling camera control yourself and disabling OrbitControls entirely.

Debugging

Enable debug mode by adding ?debugorbit to your URL:

This shows:

  • Camera look target as a green sphere

  • Raycast hit points

  • Detailed logging of camera operations

Other debug parameters:

  • ?freecam - Unlock all camera restrictions

  • ?smoothcam or ?smoothcam=0.95 - Override damping factor

  • ?debugcamerafit - Log camera fitting operations

More Information

API Documentation:

Related Components:

Last updated