M MY Multiplayer: Wiki
Side
Kind

processLineOfSight

Client

Casts a ray between two points and returns the first thing it hits.

bool, vec3, vec3, element|nil processLineOfSight(float startX, startY, startZ, float endX, endY, endZ [, bool checkBuildings = true, bool checkVehicles = true, bool checkPeds = true, bool checkObjects = true])

Parameters

NameTypeDescription
startX, startY, startZfloatWhere the ray starts. A vec3 also works.
endX, endY, endZfloatWhere the ray ends. A vec3 also works.
checkBuildingsboolWhether buildings count.default true
checkVehiclesboolWhether vehicles count.default true
checkPedsboolWhether peds count.default true
checkObjectsboolWhether objects count.default true

Returns

false if nothing was hit. Otherwise true, the hit point, the surface normal there and the element hit (nil when it is not an element, such as a map building).

Example

local function firstHit(from, to)
    local hit, position, normal, element = processLineOfSight(from, to, true, true, false, true)
    if hit and element then
        outputDebugString("Hit a " .. getElementType(element))
    end
    return hit and position
end

See also