Skip to content

camera.attach

Has a player’s camera follow a target: a player, a vehicle, a ped, or one of your objects. The camera sits at offset from the target and looks at lookAtOffset from it, and it stays with the target as it moves or comes back into view. The player keeps playing. playerCameraChangeRequest is asked first.

camera.attach(viewer: PlayerTarget, target: CameraTarget, offset: Vector3, lookAtOffset: Vector3, angleRadians?: number,
options?: ViewListenOptions): Promise<ActionResult>
Name Type Description
viewer PlayerTarget The player whose camera it is.
target CameraTarget What the camera follows.
offset Vector3 Where the camera is, from the target, in metres.
lookAtOffset Vector3 The point it looks at, from the target.
angleRadians number Optional. Turns the camera around the target. Defaults to 0.
options ViewListenOptions Optional. listenAtView: true: the viewer hears nearby chat at the target instead of where their character is.

A promise of an ActionResult: applied once the camera follows the target, rejected with a code, or timeout after 21 seconds without an answer.

Code Meaning
view-denied playerCameraChangeRequest refused it.
target-not-found No such player, vehicle, ped or object.
invalid-value options.listenAtView is not a boolean.
target-in-another-world The target is in another virtual world than the player.
spectating-active The player is spectating: players.stopSpectating first.
player-not-found No such player, or they left meanwhile.

A chase camera behind the getaway car.

gamemodes/my-mode.ts
import { camera, commands, vehicles } from "nativemp";
commands.register("chasecam", async (player, args) => {
const car = vehicles.listOwn().find((vehicle) => vehicle.id === Number(args));
if (car) await camera.attach(player, { kind: "vehicle", networkId: car.id }, [0, -8, 3], [0, 0, 1.5]);
});