this is what I personally use and it works
public static int GetPedInFront(int ignore, float range = 2.00f) { try { int playerCount = GetNumberOfPlayers(); Vector3 ignorePos = GetEntityCoords(ignore, true); for (int i = 0; i < playerCount; i++) { int ped = GetPlayerPed(i); if (ped != ignore) { Vector3 pedPos = GetEntityCoords(ped, true); float distance = GetDistanceBetweenCoords(pedPos.X, pedPos.Y, pedPos.Z, ignorePos.X, ignorePos.Y, ignorePos.Z, false); if (distance < range) { return ped; } } } } catch (Exception ex) { Debug.WriteLine($"Ex -> {ex}"); } return 0; }