Note: The PlayerCamera script must be executed in Local mode. Any script that manipulates the player’s camera must be executed in Local mode.
Note: These options apply only to Meta Horizon Worlds Web and Mobile, which means web and mobile users.
Tip: This setting is applied when the player enters the world. Later, during runtime, you may use the Camera API to dynamically set the camera to a new point of view, as needed.
Force HWXS Camera option | Description |
---|---|
None | Camera point of view is not forced for web and mobile users. |
Third Person | Camera POV is set to third-person. |
First Person | Camera POV is set to first-person. |
Orbit | Camera POV is set to orbit the player. |
Pan | Camera POV is set at a fixed distance and angle from the player. |
Perspective | Description | Use cases |
---|---|---|
First Person | Camera and the player avatar’s eyes are in the same location. Camera is facing forward from the player’s avatar. | This is the default camera for VR. In general, first person is used to focus the player’s attention on tasks like aiming or reading from user interfaces. However, the player can lose track of other activities or threats on the periphery. |
Third Person | Camera is positioned behind the player’s avatar, facing forward of the avatar. | Third person is often used for close quarters combat or navigation or to build connection between the player and their avatar. If the environment requires being able to see more widely than the first-person camera, the third-person option can enhance the experience. |
Orbit | Orbit camera allows the player to pivot the position of the camera around a fixed point. | Orbit camera is useful for visual exploration of a specific area or object. |
Focused Interaction | For web and mobile, the Focused Interaction API allows for zooming the camera into a specific object to enable a limited range of interactions. Note: Not included in this world. For more information, see the Developing for Web and Mobile tutorial world. | This is useful for things like entering codes in a keypad or manipulating a puzzle. |
Fixed Camera Position | This mode places the camera at a fixed position in the world, facing in a fixed direction. | The fixed camera position can be used for big vistas or cutscenes that do not center on a specific entity. |
Fixed Camera Position with Entity | This mode places the camera at a fixed position, while tracking an entity, such as the player’s avatar. | Use this camera to build player-centric cutscenes or to build isometric or sidescrolling games that focus on the player’s avatar. |
PlayerCameraManager.ts
- script that manages assignment of PlayerCameras, among other things.PlayerCamera.ts
- script that controls the camera of the player’s avatar to which it is assigned.Tip: Script properties set on other entities, such as the sword, which usesWeapon.ts
, are passed as event message data into these scripts.
export const PlayerCameraEvents = {
SetCameraMode: new hz.NetworkEvent<{ mode: CameraMode}>('SetCameraMode'),
SetCameraFixedPosition: new hz.NetworkEvent<{position: hz.Vec3, rotation: hz.Quaternion, duration: number, easing: Easing}>('SetCameraFixedPosition'),
SetCameraFixedPositionWithEntity: new hz.NetworkEvent<{entity: hz.Entity, duration: number, easing: Easing}>('SetCameraFixedPositionWithEntity'),
RevertPlayerCamera: new hz.NetworkEvent<{}>('RevertPlayerCamera'),
OnCameraResetPressed: new hz.NetworkEvent<{player: hz.Player}>('OnCameraResetPressed'),
};
PlayerCamera.ts
script sets the camera to a new mode. Example event:this.sendNetworkEvent(player, PlayerCameraEvents.SetCameraMode, {mode: CameraMode.ThirdPerson});
mode
must match up to the values for a supported camera mode, which are defined using the CameraMode enum:export declare enum CameraMode {
FirstPerson = 0,
ThirdPerson = 1,
Attach = 2,
Fixed = 3,
Orbit = 4,
Pan = 5
};
Weapon.ts
script, which is attached to the sword, the field CameraMode is set to ThirdPerson. This value is passed into the event:this.sendNetworkEvent(player, PlayerCameraEvents.SetCameraMode, {mode: this.getCameraMode()});
Tip: Whenever you are changing the camera to a new mode or point of view, you should retain the value for the old camera mode to enable a smooth switch back to the previous mode, if needed.
this.sendNetworkEvent(player, PlayerCameraEvents.SetCameraFixedPosition, { position: new Vec3 (0,20,0), rotation: new Quaternion (0,0,0,1), duration: 0.4, easing: Easing.EaseInOut});
Parameter | Description |
---|---|
position | The world coordinates in Vec3 format for the position of the PlayerCamera. |
rotation | The rotational coordinates in Vec3 format for where the camera is pointed. |
duration | The duration of the transition between camera modes, in seconds. |
easing | You can set the method of transitioning in and out of the new camera point of view, using the following set of enum values. |
export declare enum Easing {
EaseIn = 0,
EaseOut = 1,
EaseInOut = 2,
Linear = 3
};
this.sendNetworkEvent(player, PlayerCameraEvents.SetCameraFixedPositionWithEntity, { entity: this.props.cameraPositionEntity, duration: 0.4, easing: Easing.EaseInOut});
FixedCameraTrigger.ts
script sends positional and directional information from an empty reference object above the trigger, which serves as the placeholder for the fixed camera.getPreviousCameraMode()
function: getPreviousCameraMode(): number {
let previousCameraMode = CameraMode.ThirdPerson;
if (this.previousCameraMode !== -1) {
previousCameraMode = this.previousCameraMode;
};
return previousCameraMode;
};
PlayerManager.ts
script simply calls the getPreviousCameraMode()
function.Note: For FixedCamera modes, a Camera Reset button should be surfaced on screen, enabling visitors to escape from FixedCamera perspectives. Otherwise, they may find themselves “stuck” in that POV and quit the world.
PlayerCamera.ts
: // Add a custom input button to enable players to reset their camera to the previous camera mode.
// We use this when the camera mode is set to Fixed to avoid players getting stuck in a fixed camera mode.
displayCameraResetButton(on: boolean) {
if (on) {
if (!this.cameraResetHasRegisteredCallback) {
this.cameraResetInput = hz.PlayerControls.connectLocalInput(hz.PlayerInputAction.LeftGrip, hz.ButtonIcon.Door, this, {preferredButtonPlacement: hz.ButtonPlacement.Default});
this.cameraResetInput.registerCallback((action, pressed) => {
if(pressed) {
this.onCameraResetButtonPressed();
};
});
this.cameraResetHasRegisteredCallback = true;
};
} else if (this.cameraResetInput !== undefined) {
this.cameraResetInput?.disconnect();
this.cameraResetHasRegisteredCallback = false;
};
};
PlayerCamera.ts
PlayerCameraManager.ts
PlayerCamera.ts
script, so that there are the same number of PlayerCamera entities as the max capacity of avatars for your world.
PlayerCamera.ts
and PlayerCameraManager.ts
to learn how to send events to these scripts.CameraManager.ts
script.