Raycast

Performs a raycast from the current camera position forward by 1000 units.

Returns:

  • hit (boolean): Whether the raycast hit something

  • endCoords (vector3): World coordinates where the raycast ended

  • surfaceNormal (vector3): Normal vector of the hit surface

  • entityHit (entity): The entity that was hit (if any)

Example:

local hit, endCoords, surfaceNormal, entityHit = ps.raycast()

if hit then
    print("Hit something at coordinates:", endCoords)
    print("Surface normal:", surfaceNormal)
    
    if entityHit and entityHit ~= 0 then
        print("Hit entity:", entityHit)
        if IsEntityAVehicle(entityHit) then
            print("Hit a vehicle!")
        elseif IsEntityAPed(entityHit) then
            print("Hit a ped!")
        end
    end
else
    print("Raycast didn't hit anything")
end

Last updated