Private
constructorClears the active camera for the specified player. Causes the specified players to end any in-progress camera perspectives, including any eased camera motions, and return to their normal perspective.
This function can't be called in read-only mode.
This function can throw errors.
import { Player } from "@minecraft/server";
// Scripting code for the `camera <player> clear` command.
function clearPlayerCamera(player: Player) {
player.camera.clear();
}
Optional
fadeCameraOptions: CameraFadeOptionsAdditional options around camera fade operations.
Optional
Begins a camera fade transition. A fade transition is a full-screen color that fades-in, holds, and then fades-out.
This function can't be called in read-only mode.
This function can throw errors.
import { Player } from "@minecraft/server";
// Scripting code for the `camera <player> fade color 0.0 0.0 1.0` command.
function sceneEndFade(player: Player) {
// fade color: blue
player.camera.fade({
fadeColor: {
red: 0.0,
green: 0.0,
blue: 1.0,
},
});
}
// Scripting code for the `camera <player> time 1.5 2.0 1.0 fade color 1.0 0.5 0.3` command.
function sceneFadeSlow(player: Player) {
// fade color: rgb (1.0, 0.5, 0.3)
player.camera.fade({
fadeTime: {
fadeInTime: 1.5,
holdTime: 2.0,
fadeOutTime: 1.0,
},
fadeColor: {
red: 1.0,
green: 1.0,
blue: 1.0,
},
});
}
Identifier of a camera preset file defined within JSON.
Optional
setOptions: CameraDefaultOptions | CameraFixedBoomOptions | CameraSetFacingOptions | CameraSetLocationOptions | CameraSetPosOptions | CameraSetRotOptionsAdditional options for the camera.
Optional
Sets the current active camera for the specified player.
This function can't be called in read-only mode.
This function can throw errors.
import { Player, EasingType, Vector3, Vector2 } from "@minecraft/server";
// Scripting code for the `camera <player> set minecraft:free ease 1.0 in_cubic pos 10 20 30 facing @e[type=wolf,c=1]` command.
function setCameraToFaceWolfAtPos(player: Player) {
const location: Vector3 = { x: 10, y: 20, z: 30 };
const wolf = player.dimension.getEntities({
type: "minecraft:wolf",
closest: 1,
})[0];
player.camera.setCamera("minecraft:free", {
location: location,
facingEntity: wolf,
easeOptions: {
easeTime: 1.0,
easeType: EasingType.InCubic,
},
});
}
// Scripting code for the `camera <player> set minecraft:free ease 2.5 in_cubic pos 10 20 30 facing 1 2 3` command.
function setCameraToFaceLocationAtPos(player: Player) {
const location: Vector3 = { x: 10, y: 20, z: 30 };
const facingLocation: Vector3 = { x: 1, y: 2, z: 3 };
player.camera.setCamera("minecraft:free", {
location: location,
facingLocation: facingLocation,
easeOptions: {
easeTime: 2.5,
easeType: EasingType.InCubic,
},
});
}
// Scripting code for the `camera <player> set minecraft:free ease 2.5 in_cubic pos 10 20 30 rot 90 0` command.
function setCameraToFaceRotAtPos(player: Player) {
const location: Vector3 = { x: 10, y: 20, z: 30 };
const rotation: Vector2 = { x: 90, y: 0 };
player.camera.setCamera("minecraft:free", {
location: location,
rotation: rotation,
easeOptions: {
easeTime: 2.5,
easeType: EasingType.InCubic,
},
});
}
import { Player, EasingType, Vector3, Vector2 } from "@minecraft/server";
// Scripting code for the `camera <player> set minecraft:free ease 2.5 in_cubic rot 90 0` command.
function setCameraToFaceRot(player: Player) {
const rotation: Vector2 = { x: 90, y: 0 };
player.camera.setCamera("minecraft:free", {
rotation: rotation,
easeOptions: {
easeTime: 2.5,
easeType: EasingType.InCubic,
},
});
}
import { Player, EasingType, Vector3 } from "@minecraft/server";
// Scripting code for the `camera <player> set minecraft:free ease 1.0 in_cubic facing @e[type=wolf,c=1]` command.
function setCameraToFaceWolf(player: Player) {
const wolf = player.dimension.getEntities({
type: "minecraft:wolf",
closest: 1,
})[0];
player.camera.setCamera("minecraft:free", {
facingEntity: wolf,
easeOptions: {
easeTime: 1.0,
easeType: EasingType.InCubic,
},
});
}
// Scripting code for the `camera <player> set minecraft:free ease 1.0 in_out_back facing 1 2 3` command.
function setCameraToFacePos(player: Player) {
const location: Vector3 = { x: 1, y: 2, z: 3 };
player.camera.setCamera("minecraft:free", {
facingLocation: location,
easeOptions: {
easeTime: 1.0,
easeType: EasingType.InOutBack,
},
});
}
import { Entity, Player, Vector2, Vector3, world } from "@minecraft/server";
// Scripting code for the `camera <player> set minecraft:free rot 0 90` command.
function setCameraToFaceEast(player: Player) {
const rotation: Vector2 = { x: 0, y: 90 };
player.camera.setCamera("minecraft:free", {
rotation: rotation,
});
}
import { Entity, Player, Vector2, Vector3, world } from "@minecraft/server";
// Scripting code for the `camera <player> set minecraft:free pos 10 20 30 facing @e[type=wolf,c=1]` command.
function setCameraToFaceWolf(player: Player) {
const wolf = player.dimension.getEntities({
type: "minecraft:wolf",
closest: 1,
})[0];
const wolfLocation: Vector3 = { x: 10, y: 20, z: 30 };
player.camera.setCamera("minecraft:free", {
facingEntity: wolf,
location: wolfLocation,
});
}
// Scripting code for the `camera <player> set minecraft:free pos 10 20 30 facing 20 20 30` command.
function setCameraToFaceLocation(player: Player) {
const location: Vector3 = { x: 10, y: 20, z: 30 };
const facingLocation: Vector3 = { x: 20, y: 20, z: 30 };
player.camera.setCamera("minecraft:free", {
facingLocation: facingLocation,
location: location,
});
}
// Scripting code for the `camera <player> set minecraft:free pos 10 20 30 rot 0 90` command.
function setCameraToFaceEast(player: Player) {
const location: Vector3 = { x: 10, y: 20, z: 30 };
const rotation: Vector2 = { x: 0, y: 90 };
player.camera.setCamera("minecraft:free", {
location: location,
rotation: rotation,
});
}
import { Player } from "@minecraft/server";
// Scripting code for the `camera <player> set minecraft:first_person` command.
function setFirstPerson(player: Player) {
player.camera.setCamera("minecraft:first_person");
}
// Scripting code for the `camera <player> set minecraft:third_person` command.
function setThirdPerson(player: Player) {
player.camera.setCamera("minecraft:third_person");
}
// Scripting code for the `camera <player> set minecraft:third_person_front` command.
function setThirdPersonFront(player: Player) {
player.camera.setCamera("minecraft:third_person_front");
}
import { Vector3Builder, Vector3Utils } from "@minecraft/math";
import { EasingType, Player, Vector3 } from "@minecraft/server";
function getAbsoluteLocationFromViewAnchor(
anchor: Vector3,
location: Vector3,
viewDirection: Vector3
) {
const dirz = new Vector3Builder(viewDirection);
const dirx = new Vector3Builder(dirz.z, 0, -dirz.x);
const diry = Vector3Utils.cross(dirz, dirx);
const xo = Vector3Utils.scale(dirx, anchor.x);
const yo = Vector3Utils.scale(diry, anchor.y);
const zo = Vector3Utils.scale(dirz, anchor.z);
return new Vector3Builder(location).add(xo).add(yo).add(zo);
}
// Scripting code for the `execute as @s at @s anchored eyes run camera @s set minecraft:free ease 0.1 linear pos ^-0.75 ^ ^-1.5 rot ~ ~` command
function setCamera(player: Player) {
const headLocation = player.getHeadLocation();
const viewDirection = player.getViewDirection();
const rotation = player.getRotation();
const anchor = new Vector3Builder(-0.75, 0, -1.5);
const location = getAbsoluteLocationFromViewAnchor(
anchor,
headLocation,
viewDirection
);
player.camera.setCamera("minecraft:free", {
location: location,
rotation: rotation,
easeOptions: {
easeTime: 0.1,
easeType: EasingType.Linear,
},
});
}
import { Entity, Player, Vector3, world } from "@minecraft/server";
// Scripting code for the `camera <player> set minecraft:free facing @e[type=wolf,c=1]` command.
function setCameraToFaceWolf(player: Player) {
const wolf = player.dimension.getEntities({
type: "minecraft:wolf",
closest: 1,
})[0];
player.camera.setCamera("minecraft:free", {
facingEntity: wolf,
});
}
// Scripting code for the `camera <player> set minecraft:free facing @e[type=wolf,c=1]` command.
function setCameraToFaceLocation(player: Player) {
const location: Vector3 = { x: 10, y: 20, z: 30 };
player.camera.setCamera("minecraft:free", {
facingLocation: location,
});
}
Contains methods relating to the active camera for the specified player.