1 ignores glass, though it doesn’t seem to work on car windows.
2 ignores see-through objects, yes including partially see-through. Worse case I’ve seen is the desk in the Paleto bank being one huge see-through entity. Vehicle windows fall under this as you mentioned.
4 is supposed to ignore “no_collision” but I’m not entirely sure what that includes (setting an entity to have no collision doesn’t work).
You can use these bits together, so passing 1|2 (or just 3) should ignore both glass and see-through objects, though I assume most glass is marked as see-through. The “default” value for this arg is 1|2|4. Mixing the flags also works (i.e. 2|4|8|16 to include vehicles, peds, ragdolls, and objects).
For the meantime I recommend flag switching and distance-checking to ensure you can target all objects and the world even when overlapping.
function RaycastFromCamera(flag)
local coords, normal = GetWorldCoordFromScreenCoord(0.5, 0.5)
local destination = coords + normal * 10
local handle = StartShapeTestLosProbe(coords.x, coords.y, coords.z, destination.x, destination.y, destination.z,
flag, PlayerPedId(), 4) -- you may want 2 or 6?
while true do
Wait(0)
local retval, hit, endCoords, surfaceNormal, materialHash, entityHit = GetShapeTestResultIncludingMaterial(handle)
if retval ~= 1 then
return hit, entityHit, endCoords, surfaceNormal, materialHash
end
end
end
local flag = 511
while isActive do
local playerCoords = GetEntityCoords(PlayerPedId())
local hit, entityHit, endCoords = RaycastFromCamera(flag)
local entityType = entityHit ~= 0 and GetEntityType(entityHit) or 0
local distance = #(playerCoords - endCoords)
if entityType == 0 then
local _flag = flag == 511 and 26 or 511
local _hit, _entityHit, _endCoords = RaycastFromCamera(_flag)
local _distance = #(playerCoords - _endCoords)
if _distance < distance then
flag, hit, entityHit, endCoords, distance = _flag, _hit, _entityHit, _endCoords, _distance
entityType = entityHit ~= 0 and GetEntityType(entityHit) or 0
end
end
-- etc..
if not next(options) then -- switch flag if the targeted entity had no registered options
flag = flag == 511 and 26 or 511
end
end