Skip to content

vehicles.setVelocity

Sets how fast a vehicle moves, in m/s, or how fast it spins about each world axis, in rad/s, once. The game then runs it on from there: gravity, the road, its driver and the traffic AI all act on it as on any other motion. A parked car starts moving. Every player sees the result.

vehicles.setVelocity(id: number, velocity: Vector3): Promise<ActionResult>
vehicles.setAngularVelocity(id: number, angularVelocity: Vector3): Promise<ActionResult>
Name Type Description
id number The vehicle’s network ID.
velocity Vector3 World-space velocity in m/s, at most 250 on each axis.
angularVelocity Vector3 World-space spin in rad/s, at most 50 on each axis.

A promise of an ActionResult. "applied" once the vehicle moves with it, and vehicles.getVelocity already reads it. Rejected with:

Code When
invalid-velocity Not three finite numbers, or over the limit on an axis.
vehicle-not-found No such vehicle, or it was removed first.
vehicle-is-train Trains follow their track.
no-simulation-owner No player is near enough to run the vehicle.
rate-limited More than 125 at once, or 50 a second, for vehicles run by one player’s game (with setAngularVelocity). Nothing was sent; call again later.
simulation-owner-changed Another player’s game took the vehicle over before the server saw the result. Read getVelocity and call again if you need to.
gamemodes/my-mode.ts
import { commands, vehicles } from "nativemp";
commands.register("jump", async (player) => {
if (player.vehicleId === null) return;
const [x, y] = vehicles.getVelocity(player.vehicleId) ?? [0, 0, 0];
await vehicles.setVelocity(player.vehicleId, [x, y, 12]);
});