This is a simple 3D distance calculation to check the distance between two Vector3's.
This was implemented at a time when alt:V didn't have these utilities.
const dist = Athena.utility.vector.distance(player.pos, player2.pos);
Same as above, but doesn't use z axis for calculation. Slightly less intensive.
const dist = Athena.utility.vector.distance2d(player.pos, player2.pos);
Given a list of entities such as a player, or a vehicle you can simply pass a list of them to get the closest type.
- player position
- player rotation
- an array of entities (players, or vehicles)
- a maximum distance to look for, anything lower is consider closer / closest.
const players = [...alt.Player.all]; const aPlayer = Athena.utility.vector.getClosestEntity<alt.Player.all>(player.pos, player.rot, players, 5);
Gets a forward vector of a player or vehicle based on their rotation.
const directionPlayerIsFacing = Athena.utility.vector.getForwardVector(player.rot);
Returns a position directly in front of a player based on distance.
const posInFrontOf = Athena.utility.vector.getVectorInFrontOfPlayer(player, 5);
Simply checks if a position is between two vector points.
- positionToCheck = vector3 position
- pos1 - vector3 position
- pos2 - vector3 position
const isBetween = Athena.utility.vector.isBetweenVectors(posToCheck, pos1, pos2);