Camera Control

Control camera movement and focus during runtime to track moving objects, create cinematic views, or guide users through your digital twin.

New Feature: Camera control features are available since realvirtual version 6.0.7.

Overview

Camera control features provide two main capabilities for runtime applications:

  1. Object Following - Continuous camera tracking that keeps a GameObject centered in view as it moves through the scene

  2. Object Focus - One-time camera movement that smoothly transitions to view a specific object

These features are essential for:

  • AGV/Mobile Robot Tracking - Follow autonomous vehicles as they navigate through facilities

  • Process Visualization - Focus on specific machines or operations during demonstrations

  • Guided Tours - Create automated camera sequences that highlight key areas

  • Operator Training - Direct user attention to important components

  • Remote Monitoring - Track critical moving equipment in real-time

Camera control integrates seamlessly with PLC signals, UI buttons, and scripting, making it suitable for both automated sequences and user-controlled interactions.

CameraFollowObject Component

The CameraFollowObject component controls camera behavior for both continuous following and one-time focus operations.

Adding CameraFollowObject

  1. Add the component to any GameObject in your scene (commonly attached to UI buttons)

  2. Assign the Object To Follow property to your target GameObject

  3. Configure distance and angle settings as needed

  4. Connect to buttons or PLC signals for triggering

Properties

Target Object

Object To Follow (GameObject) - The GameObject to track or focus on. This can be any object in your scene including MUs, robots, conveyors, or machine components. The camera will automatically calculate the object's bounding box center from all child renderers.

Camera Distance

Use Custom Distance (boolean) - Controls whether to use a manually specified distance or auto-calculate the optimal viewing distance. When disabled, the camera automatically calculates the distance needed to fit the object at approximately 1/3 of screen space, providing a comfortable viewing size that shows the object clearly without filling the entire frame.

Distance (float, meters) - Camera distance from the object center when Use Custom Distance is enabled. Adjust this value to control how close or far the camera appears from the target. Typical values range from 2 meters for small objects to 20 meters for large equipment.

Camera Angle

Use Custom View Angle (boolean) - Controls whether to use a manually specified camera rotation or auto-select the optimal angle. When disabled for FocusOnObject, the camera calculates an optimal viewpoint slightly above and to the side of the object. When disabled for StartFollowing, the current camera angle is maintained.

View Angle (Vector3, degrees) - Camera rotation in Euler angles (X, Y, Z) when Use Custom View Angle is enabled. Use this to set precise camera orientations such as top view (90, 0, 0) or side view (0, 90, 0).

User Control Options

Allow Rotation (boolean) - When enabled during following mode, users can orbit the camera around the object using mouse or touch input while the object remains centered. This is useful for inspection scenarios where operators need to examine moving equipment from different angles.

Allow Zoom (boolean) - When enabled during following mode, users can adjust the camera distance from the object using scroll wheel or pinch gestures while maintaining focus on the target. Combine with Allow Rotation for full user control during tracking.

Follow Mode

Auto Start Following (boolean) - Automatically begins following the target object when the scene starts or when the component is enabled. Enable this for scenarios where tracking should start immediately, such as startup demonstrations or monitoring views.

PLC Signal Control

PLC Signal Start Following (PLCInputBool) - PLC signal that controls following mode. When the signal transitions to true, following begins. When the signal returns to false, following stops automatically. Use this for automated sequences controlled by your PLC logic.

Follow Active (boolean) - Public boolean property that can be controlled externally by scripts or PLCOutputBool components. Set to true to start following, false to stop. This provides an alternative to PLC signals for scripting scenarios or UI toggle buttons.

💡 Hint PLC signal monitoring uses FixedUpdate timing to ensure synchronization with PLC communication cycles. Either the PLC signal or Follow Active bool can trigger following - both do not need to be true simultaneously.

Control Methods

The CameraFollowObject component provides three main methods that can be triggered from UI buttons, scripts, or other events:

StartFollowing()

Begins continuous camera tracking of the target object. The camera will smoothly move to the configured viewing position and then continuously update its position to keep the object centered as it moves. Following continues until explicitly stopped by calling StopFollowing() or by setting control signals to false.

Use Cases:

  • Track AGVs moving through warehouses

  • Follow robotic arms during operation sequences

  • Monitor conveyor transport of critical products

  • Automated camera sequences in demonstrations

Button Setup: Add a button to your UI and connect its OnClick event to CameraFollowObject.StartFollowing(). For toggle behavior, use ToggleFollowing() instead.

StopFollowing()

Ends continuous camera tracking and returns the camera to normal user-controlled navigation mode. The camera remains at its current position and rotation, allowing users to navigate freely.

Use Cases:

  • End automated tracking sequences

  • Return control to operators

  • Switch between tracked objects

FocusOnObject()

Performs a one-time smooth camera movement to view the target object without continuous tracking. The camera will interpolate to the optimal viewing position, but will not continue following if the object moves afterward. This is ideal for guided tours or drawing attention to specific components.

Use Cases:

  • Highlight specific machines during presentations

  • Create waypoint-based guided tours

  • Quick navigation to specific areas

  • Operator attention management in training scenarios

ToggleFollowing()

Switches between following and not following states. If currently following, this method stops tracking. If not following, it starts tracking. Useful for toggle buttons in your UI.

Inspector Buttons

The component provides three buttons directly in the Inspector for testing during development:

  • Start Following - Test continuous tracking

  • Stop Following - End tracking

  • Focus On Object - Test one-time focus

These buttons work in both Edit mode and Play mode, allowing you to preview camera behavior during scene setup.

Distance and Angle Auto-Calculation

When custom distance or angle options are disabled, the camera uses intelligent auto-calculation:

Auto Distance Calculation:

  • Analyzes all renderers on the target object and its children

  • Calculates combined bounding box dimensions

  • Determines distance to fit object at 1/3 screen space

  • Adds safety margin based on object size

  • Ensures object is clearly visible without being too close or far

Auto Angle Calculation:

  • FocusOnObject: Calculates optimal viewpoint slightly elevated and offset from object center for best visibility

  • StartFollowing: Maintains current camera angle to avoid disorienting users during tracking

💡 Hint Auto-calculation works best with objects that have MeshRenderer or SkinnedMeshRenderer components. For objects without renderers, the camera uses the object's transform position and a default distance of 5 meters.

Camera Position Management

realvirtual includes a camera position system for saving and loading predefined views, useful for creating camera presets and start positions.

CameraPos ScriptableObject

CameraPos is a ScriptableObject that stores complete camera state including:

  • Target Position - The point the camera is looking at

  • Camera Distance - Distance from target to camera

  • Camera Rotation - Camera orientation as Euler angles

  • Orthographic Settings - Main view and ortho overlay states

  • Lock Status - Prevents accidental modification of saved positions

Creating CameraPos Assets:

  1. Right-click in Project window

  2. Select Create > realvirtual > Add Camera Position

  3. Name the asset descriptively (e.g., "MainOverview", "RobotStation1")

  4. The asset automatically saves current camera state in Edit mode

SceneMouseNavigation Integration

The SceneMouseNavigation component (attached to Main Camera) provides methods for camera position management:

SetNewCameraPosition()

public void SetNewCameraPosition(Vector3 targetPos, float camDistance, Vector3 camRotation, bool noInterpolate = false)

Moves the camera to a specific position with optional smooth interpolation. Used internally by CameraPos loading and can be called from scripts for dynamic camera placement.

Parameters:

  • targetPos - The world position the camera should look at

  • camDistance - Distance from target to camera in meters

  • camRotation - Camera rotation as Euler angles (X, Y, Z)

  • noInterpolate - If true, jump immediately; if false, smoothly interpolate

SetCameraPosOnStartPlay

When enabled on SceneMouseNavigation, automatically loads the specified Last Camera Position (CameraPos asset) when entering Play mode. This ensures consistent starting views for testing and published applications.

SaveCameraPosOnQuit

When enabled, automatically saves the current camera state to the Last Camera Position asset when exiting Play mode or quitting the application. This preserves the user's camera position between sessions.

StartCameraPosition Script

The StartCameraPosition script (found in UIPrefabs) provides a simple way to connect UI buttons to camera positions:

  1. Attach StartCameraPosition to a UI button GameObject

  2. Assign a CameraPos asset to the Camera Position property

  3. Connect the button's OnClick event to StartCameraPosition.SetCameraPosition()

  4. Clicking the button loads the saved camera view

Use Cases:

  • Create "Home" or "Reset View" buttons

  • Build camera preset libraries for different areas

  • Quick navigation in large digital twins

  • Standardized training viewpoints

Usage Examples

Example 1: AGV Tracking with Auto Distance

Track an autonomous guided vehicle with automatic distance calculation:

  1. Create an empty GameObject named "AGVCameraControl"

  2. Add CameraFollowObject component

  3. Set Object To Follow to your AGV GameObject

  4. Leave Use Custom Distance disabled for auto-calculation

  5. Leave Use Custom View Angle disabled to maintain current view

  6. Set Auto Start Following to true for immediate tracking

When Play starts, the camera automatically follows the AGV at an optimal distance that keeps it clearly visible.

Example 2: Robot Inspection with User Control

Create an interactive robot inspection mode where users can rotate around while tracking:

  1. Add CameraFollowObject to a UI button GameObject

  2. Set Object To Follow to your robot GameObject

  3. Enable Allow Rotation to permit user orbiting

  4. Enable Allow Zoom for distance adjustment

  5. Connect button OnClick to CameraFollowObject.StartFollowing()

Users can click the button to start tracking, then freely rotate and zoom while the robot remains centered.

Example 3: PLC-Controlled Machine Focus

Focus on a specific machine when a PLC signal indicates operation start:

  1. Add CameraFollowObject to a GameObject in your scene

  2. Set Object To Follow to the machine

  3. Create a PLCInputBool signal component for "MachineRunning"

  4. Assign this signal to PLC Signal Start Following

  5. Set custom distance and angle for optimal machine view

When the PLC signal goes high, the camera automatically starts following the machine. When the signal goes low, tracking stops.

Example 4: Guided Tour Waypoints

Create a guided tour with multiple focus points:

  1. Add CameraFollowObject components to multiple UI buttons

  2. Assign different objects to each (Station1, Station2, etc.)

  3. Configure custom view angles for each station

  4. Connect buttons to FocusOnObject() method

Users can click buttons to smoothly move the camera to different tour stops without continuous tracking.

Example 5: Conveyor Product Tracking

Track products moving on conveyors with locked camera angle:

  1. Add CameraFollowObject to a monitor display GameObject

  2. Set Object To Follow to your MU product

  3. Enable Use Custom View Angle

  4. Set View Angle to side view (0, 90, 0)

  5. Disable Allow Rotation and Allow Zoom

  6. Enable Auto Start Following

The camera maintains a fixed side view angle while smoothly tracking the product along the conveyor.

Example 6: Camera Position Presets

Create a set of camera presets for different areas:

  1. Navigate camera to first desired position in Edit mode

  2. Create CameraPos asset (right-click > Create > realvirtual > Add Camera Position)

  3. Name it "Overview1"

  4. Repeat for additional positions (Overview2, DetailView, etc.)

  5. Add StartCameraPosition scripts to UI buttons

  6. Assign respective CameraPos assets

  7. Connect buttons to SetCameraPosition()

Users can quickly jump between predefined views by clicking buttons.

Example 7: Monitoring Dashboard

Create a multi-camera monitoring view with automatic switching:

  1. Create multiple CameraFollowObject components for different zones

  2. Use Follow Active boolean for script control

  3. Create a timer script that cycles through zones:

public class MonitoringCycle : MonoBehaviour
{
    public CameraFollowObject[] zones;
    public float cycleTime = 10f;
    private int currentZone = 0;

    void Start()
    {
        InvokeRepeating("SwitchZone", 0, cycleTime);
    }

    void SwitchZone()
    {
        // Stop current zone
        if (currentZone < zones.Length)
            zones[currentZone].StopFollowing();

        // Move to next zone
        currentZone = (currentZone + 1) % zones.Length;
        zones[currentZone].StartFollowing();
    }
}

The camera automatically cycles through different monitoring zones every few seconds.

Integration with Existing Features

Scene Navigation

Camera control features work alongside standard SceneMouseNavigation capabilities:

  • Mouse/Touch Navigation - When not following, full navigation is available

  • First Person Controller - Following mode automatically disables first person mode

  • Cinemachine - Following mode deactivates Cinemachine if active

  • Orthographic Views - Camera control respects perspective/orthographic mode

  • Hotkeys - Standard view hotkeys are blocked during locked following

PLC Integration

Camera control supports full PLC integration through signal connections:

Input Signals:

  • Connect PLCInputBool to PLC Signal Start Following for automated tracking

  • Use PLCOutputBool to control Follow Active boolean from PLC logic

  • Combine with other PLC signals for complex automation sequences

Example PLC Scenario:

When AGV enters zone 1: Signal triggers camera to follow AGV
When AGV exits zone 1: Signal releases camera control
When emergency stop: Signal forces camera to focus on emergency location

User Interface

Runtime UI Integration:

  • Add buttons to top menu bar or custom panels

  • Use GenericButton components for consistent styling

  • Connect to CameraFollowObject public methods

  • Create toggle buttons for follow/unfollow behavior

Recommended UI Patterns:

  • "Follow" button with icon indication when active

  • Dropdown menu for camera preset selection

  • "Reset View" button to return to home position

  • Zone-specific focus buttons for different areas

Best Practices

Performance Considerations

  • Renderer Count - Auto-distance calculation analyzes all child renderers; complex objects with many renderers may have slight calculation overhead

  • Update Frequency - Following updates in LateUpdate every frame; consider this for performance-critical applications

  • Signal Polling - PLC signal monitoring occurs in FixedUpdate (typically 50Hz)

User Experience

  • Smooth Transitions - Use interpolation (enabled by default) for professional camera movements

  • User Control - Consider allowing rotation/zoom during following for interactive scenarios

  • Visual Feedback - Provide UI indication when camera is in follow mode

  • Exit Strategy - Always provide clear way for users to stop following and regain control

Design Guidelines

  • Auto vs Custom Distance - Use auto-calculation initially, switch to custom only if specific framing is required

  • Rotation Limits - Standard camera rotation limits still apply during following

  • Object Selection - Ensure target objects have renderers for accurate bounding box calculation

  • Multiple Trackers - Only one CameraFollowObject should control camera at a time

Troubleshooting

Camera doesn't follow object:

  • Verify Object To Follow is assigned and not null

  • Check that object hasn't been destroyed during runtime

  • Ensure no other camera control systems are active simultaneously

  • Verify PLC signals or Follow Active bool are set correctly

Distance seems incorrect:

  • Check if object has valid MeshRenderer or SkinnedMeshRenderer components

  • Try enabling Use Custom Distance and adjusting manually

  • Verify object bounds are calculated correctly (very small or very large objects may need custom distance)

Camera jumps or stutters:

  • Ensure target object is moving smoothly (not teleporting)

  • Check interpolation settings on SceneMouseNavigation

  • Verify no conflicting camera control scripts are active

See Also


© 2025 realvirtual GmbH https://realvirtual.io - All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including printing, saving, photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

Last updated