Hey i find that :

```
-- Get entity in front of player
function GetEntInFrontOfPlayer(Distance, Ped)
local Ent = nil
local CoA = GetEntityCoords(Ped, 1)
local CoB = GetOffsetFromEntityInWorldCoords(Ped, 0.0, Distance, 0.0)
local RayHandle = StartShapeTestRay(CoA.x, CoA.y, CoA.z, CoB.x, CoB.y, CoB.z, -1, Ped, 0)
local A,B,C,D,Ent = GetRaycastResult(RayHandle)
return Ent
end
-- Camera's coords
function GetCoordsFromCam(distance)
local rot = GetGameplayCamRot(2)
local coord = GetGameplayCamCoord()
local tZ = rot.z * 0.0174532924
local tX = rot.x * 0.0174532924
local num = math.abs(math.cos(tX))
newCoordX = coord.x + (-math.sin(tZ)) * (num + distance)
newCoordY = coord.y + (math.cos(tZ)) * (num + distance)
newCoordZ = coord.z + (math.sin(tX) * 8.0)
return newCoordX, newCoordY, newCoordZ
end
-- Get entity's ID and coords from where player sis targeting
function Target(Distance, Ped)
local Entity = nil
local camCoords = GetGameplayCamCoord()
local farCoordsX, farCoordsY, farCoordsZ = GetCoordsFromCam(Distance)
local RayHandle = StartShapeTestRay(camCoords.x, camCoords.y, camCoords.z, farCoordsX, farCoordsY, farCoordsZ, -1, Ped, 0)
local A,B,C,D,Entity = GetRaycastResult(RayHandle)
return Entity, farCoordsX, farCoordsY, farCoordsZ
end
```

In JS :

```
function GetEntInFrontOfPlayer(Distance, Ped) {
let CoA = GetEntityCoords(Ped, true);
let CoB = GetOffsetFromEntityInWorldCoords(Ped, 0.0, Distance, 0.0)
let RayHandle = StartShapeTestRay(CoA[0], CoA[1], CoA[2], CoB[0], CoB[1], CoB[2], -1, Ped, 0);
let A, B, C, D, Ent = GetRaycastResult(RayHandle)
return Ent;
}
//Camera's coords
function GetCoordsFromCam(distance) {
let rot = GetGameplayCamRot(2);
let coord = GetGameplayCamCoord();
let tZ = rot[2] * 0.0174532924;
let tX = rot[0] * 0.0174532924;
let num = Math.abs(Math.cos(tX));
let newCoordX = coord[0] + (-Math.sin(tZ)) * (num + distance);
let newCoordY = coord[1] + (Math.cos(tZ)) * (num + distance);
let newCoordZ = coord[2] + (Math.sin(tX) * 8.0);
return [newCoordX, newCoordY, newCoordZ];
}
// Get entity's ID and coords from where player sis targeting
function Target(Distance, Ped) {
let camCoords = GetGameplayCamCoord();
let [farCoordsX, farCoordsY, farCoordsZ] = GetCoordsFromCam(Distance);
let RayHandle = StartShapeTestRay(camCoords[0], camCoords[1], camCoords[2], farCoordsX, farCoordsY, farCoordsZ, -1, Ped, 0);
let A, B, C, D, Entity = GetRaycastResult(RayHandle);
return [Entity, farCoordsX, farCoordsY, farCoordsZ];
}
setTick(() => {
var target = Target(2, PlayerPedId());
console.log(target);
});
```