Skip to content

players.freecam

Has viewer fly a free camera: the mouse looks, WASD flies along the view, Space and Ctrl rise and sink, and holding Shift (Cross or A on a controller) flies at fastSpeed. Their character is hidden at the camera, so the world loads around it, and it can neither act nor be hurt, as while spectating.

The freecam ends with players.stopFreecam, which also picks where the player lands, and playerViewEnded says so with mode: "freecam".

players.freecam(viewer: PlayerTarget, options?: FreecamOptions): Promise<ActionResult>
Name Type Description
viewer PlayerTarget The player who flies.
options FreecamOptions Optional. How fast they fly; 12 m/s, and four times that with Shift, by default. listenAtView: true: they hear nearby chat at the camera instead of where they started flying.

A promise of an ActionResult: applied once they fly, rejected with a code, or timeout after 21 seconds without an answer.

Code Meaning
invalid-freecam-speed A speed is not a number from 0.5 to 500.
invalid-value options.listenAtView is not a boolean.
spectating-active The viewer is spectating; stop that first.
freecam-active The viewer is already flying; use players.setFreecamSpeed to change speed.
view-change-pending The viewer is still coming back from their last view; try again in a moment.
view-decision-pending Your gamemode is still deciding on a view change for this player; try again once it has answered.
resource-unavailable The viewer’s game has no room to load more of the world right now.
player-not-found No such player, or they left meanwhile.
gamemodes/my-mode.ts
import { commands, players } from "nativemp";
commands.register("fly", async (player) => {
await players.freecam(player, { speed: 20 });
});