ICameraService

Camera Service

Interface

This service provides access to all camera related functionality: Main camera state, player camera settings, camera shake, and target overrides.

Remarks

In spatial there is a single internally managed Main Camera, which is driven by various VirtualCameras. The default Actor Camera is a virtual camera that follows the player actor. This can be overridden using the SpatialVirtualCamera component.

Spatial limits access to the internal Main Camera component. This service provides a limited subset of useful camera properties and functions. Most properties and methods implement the corresponding member from Unity's Camera class.

Properties

allowPlayerToSwitchXRCameraMode

Allows a player in XR to switch between first person and third person modes

cameraToWorldMatrix

Matrix that transforms from camera space to world space (Read Only). Unity docs

firstPersonFov

The field of view while the actor camera is in first person mode.

forceFirstPerson

When true the actor camera will be forced into first person mode.

forward

The world space forward vector of the main camera

kickDecay

The speed at which camera kicks return to zero.

lockCameraRotation

When true the user will be unable to rotate the actor camera.

maxZoomDistance

The maximum 3rd person camera zoom distance for the actor camera.

minZoomDistance

The minimum 3rd person camera zoom distance for the actor camera.

pixelHeight

How tall is the camera in pixels (not accounting for dynamic resolution scaling) (Read Only). Unity docs

pixelWidth

How wide is the camera in pixels (not accounting for dynamic resolution scaling) (Read Only). Unity docs

position

The world position of the main camera

projectionMatrix

Gets the projection matrix of the camera. (Read Only). Unity docs

rect

Main camera rect (Read Only).

rotation

The world rotation of the main camera

rotationMode

The method of rotation for the actor camera with respect to player inputs. How should the camera be controlled?

scaledPixelHeight

How tall is the camera in pixels (accounting for dynamic resolution scaling) (Read Only). Unity docs

scaledPixelWidth

How wide is the camera in pixels (accounting for dynamic resolution scaling) (Read Only). Unity docs

shakeAmplitude

The intensity of camera shakes.

shakeFrequency

The speed at which camera shakes vibrate

targetOverride

The current transform overriding the actor camera.

thirdPersonFov

The field of view while the actor camera is in third person mode.

thirdPersonOffset

A translation offset applied to the actor camera in relation to the player actor. This value is rotated with the look direction, meaning a value of (1,0,0) will always keep the player on the left side of the screen.

velocity

Get the world-space speed of the camera (Read Only). Unity docs

virtualCameraBlendTime

The blend time in seconds for virtual camera transitions. Default is 0.6 seconds.

wobbleAmplitude

The intensity of camera wobbles. Wobbles are low frequency shakes.

wobbleFrequency

The speed at which camera wobbles vibrate. Wobbles are low frequency shakes.

worldToCameraMatrix

Matrix that transforms from world to camera space. (Read Only). Unity docs

xrCameraMode

The camera mode for players using an XR headset Note that this changing this will not have effect while a virtual camera is currently rendering

zoomDistance

The current 3rd person camera distance from the player actor.

Methods

CalculateFrustumCorners(Rect, float, MonoOrStereoscopicEye, Vector3[])

Given viewport coordinates, calculates the view space vectors pointing to the four frustum corners at the specified camera depth. Unity docs

CalculateFrustumPlanes()

Calculates frustum planes using the worldToProjection matrix from the main camera. Equivalent to GeometryUtility.CalculateFrustumPlanes(Camera.main). Unity docs

CalculateObliqueMatrix(Vector4)

Calculates and returns oblique near-plane projection matrix. Unity docs

ClearTargetOverride()

Clear the current actor camera target override.

CopyFromMainCamera(Camera)

Returns a copy of the main camera. This is useful for creating a new camera with the same properties and transform as the main camera. Unity docs

GetStereoProjectionMatrix(StereoscopicEye)

Gets the projection matrix of a specific left or right stereoscopic eye. (Read Only). Unity docs

GetStereoViewMatrix(StereoscopicEye)

Gets the left or right view matrix of a specific stereoscopic eye. (Read Only). Unity docs

Kick(Vector2)

Apply a temporary angular offset to the player camera, think recoil for a first person shooter.

Given a zero-ed out initial rotation, the camera will rotate to the given degrees offset, then return to zero over time. The rotation is applied with a parabolic function over time using kickDecay to drive the slope. A larger kickDecay creates a shorter/faster kick.Kicks are additive, but there can only be one active kick. This means two kicks in rapid succession can combine to create a larger kick, but two kicks in instant succession (during the same frame) will override each other, and will not produce a larger kick.

ScreenPointToRay(Vector3)

Returns a ray going from camera through a screen point. Unity docs

ScreenPointToRay(Vector3, MonoOrStereoscopicEye)

Returns a ray going from camera through a screen point. Unity docs

ScreenToViewportPoint(Vector3)

Transforms position from screen space into viewport space. Unity docs

ScreenToWorldPoint(Vector3)

Transforms a point from screen space into world space, where world space is defined as the coordinate system at the very top of your game's hierarchy. Unity docs

ScreenToWorldPoint(Vector3, MonoOrStereoscopicEye)

Transforms a point from screen space into world space, where world space is defined as the coordinate system at the very top of your game's hierarchy. Unity docs

SetTargetOverride(Transform, SpatialCameraMode)

Override the actor camera to follow a given transform.

Shake(Vector3)

Apply a high frequency shake to the player camera and all virtual cameras. Good for short, low to high intensity impacts.

Shake(float)

Apply a high frequency shake to the player camera and all virtual cameras. Good for short, low to high intensity impacts.

ViewportPointToRay(Vector3)

Returns a ray going from camera through a viewport point. Unity docs

ViewportPointToRay(Vector3, MonoOrStereoscopicEye)

Returns a ray going from camera through a viewport point. Unity docs

ViewportToScreenPoint(Vector3)

Transforms position from viewport space into screen space. Unity docs

ViewportToWorldPoint(Vector3)

Transforms position from viewport space into world space. Unity docs

Wobble(Vector3)

Apply a low frequency shake to the player camera and all virtual cameras. Good for longer high intensity impacts. Makes the camera feel dazed or off balance.

Wobble(float)

Apply a low frequency shake to the player camera and all virtual cameras. Good for longer high intensity impacts. Makes the camera feel dazed or off balance.

WorldToScreenPoint(Vector3)

Transforms position from world space into screen space. Unity docs

WorldToScreenPoint(Vector3, MonoOrStereoscopicEye)

Transforms position from world space into screen space. Unity docs

WorldToViewportPoint(Vector3)

Transforms position from world space into viewport space. Unity docs

WorldToViewportPoint(Vector3, MonoOrStereoscopicEye)

Transforms position from world space into viewport space. Unity docs