GetEntityVelocity

From GT-MP
Jump to: navigation, search
GetEntityVelocity
Client-Side Function
System-users.png Client-Side Javascript.png JavaScript

Client-side Function Description

Syntax

API.getEntityVelocity(LocalHandle entity);

Required Arguments

  • entity: parameter input should be in LocalHandle type.

NOTE: This function returns data in Vector3 type.

Usage example(s)

API.getEntityVelocity(LocalHandle entity);

Show vehicle speed in chat

API.onUpdate.connect(function() {
	var player = API.getLocalPlayer();
	if(!API.isPlayerInAnyVehicle(player)) {
		return;
	}
	
	var car = API.getPlayerVehicle(player);
	var velocity = API.getEntityVelocity(car);
	var speed = Math.sqrt(
		velocity.X * velocity.X +
		velocity.Y * velocity.Y +
		velocity.Z * velocity.Z
	);
	
	speed = speed * 3.6;
	
	API.sendChatMessage(Math.round(speed) + ' km/h')
});


References