🚢
Airship
  • Getting Started
    • Welcome to Airship
    • Installing Airship
  • TypeScript
    • Overview
    • AirshipBehaviour
      • Adding Inspector Properties
      • AirshipSingleton
      • Using Component Decorators
      • Accessing Other Components
  • Publishing
    • Publish Game
    • Developer Console
  • Networking
    • Multiplayer
    • Local Server Mode
    • Network Signals
    • Network Functions
    • Network Identity
    • Network Transform
  • Input
    • User Input
      • Actions
      • Keyboard
      • Mouse
    • Proximity Prompts
  • Core Package
    • What is the Core Package?
    • Chat Commands
    • Inventory
    • Spawning Characters
    • Enable / Disable Core Features
  • Physics
    • Physics Settings
    • Physics Layers
  • Platform Services
    • Data Store
      • Locking
    • Cache Store
    • Leaderboards
    • Platform Inventory
    • Server Management
    • Server List
    • Server Transfers
    • Users
    • Parties
    • Matchmaking
    • External Services
  • CHARACTERS
    • Quick Configuration
    • Character Movement System
      • Character Movement Data
      • Character Movement Events
    • Character Camera
      • First Person Camera
      • Simple Usage
      • Camera Structure
      • Default Camera Modes
      • Disabling the Camera System
    • Character Animations
      • Character Blender Animations
      • Character Ragdoll
  • Accessories
    • Accessories Intro
    • Creating Accessories
    • Using Accessories
  • ANIMATIONS
    • Animation Events
  • Optimization
    • Live Game Profiler
    • Reducing Bundle Size
  • Game Settings
    • Game Visibility
  • Other
    • Project Status
    • FAQ
    • DataType Math
    • JS to Luau
    • Tags
    • Terrain
    • AirshipNetworkBehaviour
      • Lifecycle Events
      • ServerRpc
      • ObserversRpc
      • TargetRpc
    • VoxelWorld
      • Voxel World Getting Started
      • Voxel World Tips
      • Prefab Voxels
      • QuarterBlocks
    • Easy Helper Utils
      • Easy Motion
      • Easy Grid Align
      • Easy Look At
      • Easy Shake
      • Easy Destroy
Powered by GitBook
On this page
  • Humanoid Camera Mode
  • Orbit Camera Mode
  • Static Camera Mode
  • Fly Camera Mode
  1. CHARACTERS
  2. Character Camera

Default Camera Modes

The camera system comes with a few pre-built camera modes.

Humanoid Camera Mode

This camera mode is the main character camera mode. It attaches to the Humanoid component.

Most likely, this will be used as the default camera.

cameraSystem.SetOnClearCallback(() => {
    return new HumanoidCameraMode(entity.GameObject, entity.Model);
});

Orbit Camera Mode

The Orbit Camera Mode attaches the camera to a Unity Transform component and lets the user rotate the camera around the transform. The distance away from the transform is locked to the value set in the constructor.

This is a useful camera mode for observing other players or objects.

const transform = otherEntity.gameObject.transform;
const distance = 3.5;

cameraSystem.SetMode(new OrbitCameraMode(distance, transform));

If you wish to use the OrbitCameraMode in the context of controlling the local player, then the entity's graphical transform must be passed to the constructor as well. This is necessary because the top-level character game object is not the same as the visual model, which will have different positioning.

const mode = new OrbitCameraMode(
    distance,
    entity.gameObject.transform,
    entity.model.transform,
);

cameraSystem.SetMode(mode);

Static Camera Mode

The Static Camera Mode simply keeps the camera in a static position and rotation.

const position = new Vector3(0, 10, 0);
const rotation = Quaternion.identity;

cameraSystem.SetMode(new StaticCameraMode(position, rotation));

Fly Camera Mode

The Fly Camera Mode allows the user to fly around the map using WASDQE keys for movement and right-click-drag for rotation.

Here is an example that sets the default camera mode to the Humanoid Camera Mode, but toggles the Fly Camera Mode when the LeftShift+P key is pressed:

let flying = false;

// Set the default camera mode to HumanoidCameraMode:
cameraSystem.SetOnClearCallback(() => {
    return new HumanoidCameraMode(entity.GameObject, entity.Model);
});

// Toggle flight mode:
function toggleFlight() {
    flying = !flying;
    if (flying) {
        // Set the new mode to FlyCameraMode:
        cameraSystem.SetMode(new FlyCameraMode());
    } else {
        // Resets to HumanoidCameraMode since that's handled
        // in the SetOnClearCallback near the top:
        cameraSystem.ClearMode();
    }
}

// Handle key presses:
keyboard.KeyDown.Connect((event) => {
    if (!keyboard.IsKeyDown(Key.LeftShift)) return;
    if (event.Key == Key.P) {
        toggleFlight();
    }
});
PreviousCamera StructureNextDisabling the Camera System

Last updated 1 year ago