Here's an example from one of my latest experiments:
local x, y, z = g_PlayerPosX, g_PlayerPosY + 35, g_PlayerPosZ
local rayX, rayY, rayZ = 0, 0, pickUpDistance
local paX, paY, paZ = rad(g_PlayerAngX), rad(g_PlayerAngY), rad(g_PlayerAngZ)
rayX, rayY, rayZ = Rotate3D(rayX, rayY, rayZ, paX, paY, paZ)
local Pobj = (IntersectAll(x, y, z, x + rayX, y + rayY, z + rayZ, 0))
if Pobj ~= 0 then
for k,v in pairs(g_Entity) do
if v.obj == Pobj then
pickUppableEntity = k
return
end
end
end
pickUppableEntity = nil
Rotate3D simply rotates the vector by the specific Euler angles, you can find it in any of my big scripts (helicopter.lua for example)
The above snippet is part of a larger script, I excecute the snippet every 10th of a second and it simply detects any active entity directly in front of the player. The rest of the script (still in development) will replace my pickuppable.lua script which allows the player to pick-up/carry/stack/drop moveable entities.
Been there, done that, got all the T-Shirts!