processLineOfSight | Multi Theft Auto: Wiki Skip to content

processLineOfSight

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function casts a ray between two points in the world, and tells you information about the point that was hit, if any. The two positions must be within the local player's draw distance as the collision data is not loaded outside this area, and the call will just fail as if the ray didn't hit.

Note

Due to a bug, shootThroughStuff argument does currently check for seeThroughStuff!

Note

Due to a bug, seeThroughStuff argument has no effect. It mistakenly checks for "shootThrough" surfaces and will always behave as if the argument is set to FALSE (It will never hit).

Syntax

bool -- hit
float float float -- hitX,​ hitY,​ hitZ
element -- hitElement
float float float -- normalX,​ normalY,​ normalZ
int -- material
float -- lighting
int -- piece
int -- worldModelID
float float float -- worldModelPositionX,​ Y,​ Z
float float float -- worldModelRotationX,​ Y,​ Z
int -- worldLODModelID
float float -- uvX,​ uvY
string -- textureName,​ string -- frameName,​ float float float -- modelHitX,​ modelHitY,​ modelHitZ processLineOfSight ( float startX, float startY, float startZ, float endX, float endY, float endZ, [ bool checkBuildings = true, bool checkVehicles = true, bool checkPlayers = true, bool checkObjects = true, bool checkDummies = true, bool seeThroughStuff = false, bool ignoreSomeObjectsForCamera = false, bool shootThroughStuff = false, element ignoredElement = nil, bool includeWorldModelInformation = false, bool bIncludeCarTyres = false, bool bIncludeExtraMateriaInfo = false ] )
Required Arguments
  • startX: The start x position
  • startY: The start y position
  • startZ: The start z position
  • endX: The end x position
  • endY: The end y position
  • endZ: The end z position
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • checkBuildings (default: true): Allow the line of sight to be blocked by GTA's internally placed buildings, i.e. the world map.
  • checkVehicles (default: true): Allow the line of sight to be blocked by vehicles .
  • checkPlayers (default: true): Allow the line of sight to be blocked by players .
  • checkObjects (default: true): Allow the line of sight to be blocked by objects .
  • checkDummies (default: true): Allow the line of sight to be blocked by GTA's internal dummies. These are not used in the current MTA version so this argument can be set to false .
  • seeThroughStuff (default: false): Allow the line of sight pass through collision materials that have this flag enabled (By default material IDs 52, 55 and 66 which are some fences that you can shoot throug but still walk on them).
  • ignoreSomeObjectsForCamera (default: false): Allow the line of sight to pass through objects that have (K) property enabled in "object.dat" data file. (i.e. Most dynamic objects like boxes or barrels)
  • shootThroughStuff (default: false): Allow the line of sight to pass through collision materials that have this flag enabled (By default material IDs 28, 29, 31, 32, 33, 74, 75, 76, 77, 78, 79, 96, 97, 98, 99, 100 which are exclusively sand / beach or underwater objects).
  • ignoredElement (default: nil): Allow the line of sight to pass through a certain specified element. This is usually set to the object you are tracing from so it does not interfere with the results.
  • includeWorldModelInformation (default: false): MISSING_PARAM_DESC
  • bIncludeCarTyres (default: false): MISSING_PARAM_DESC
  • bIncludeExtraMateriaInfo (default: false): MISSING_PARAM_DESC

Returns

  • bool -- hit float float float -- hitX: value1
  • hitY: value2
  • hitZ element -- hitElement float float float -- normalX: value3
  • normalY: value4
  • normalZ int -- material float -- lighting int -- piece int -- worldModelID float float float -- worldModelPositionX: value5
  • Y: value6
  • Z float float float -- worldModelRotationX: value7
  • Y: value8
  • Z int -- worldLODModelID float float -- uvX: value9
  • uvY string -- textureName: value10
  • string -- frameName: value11
  • float float float -- modelHitX: value12
  • modelHitY: value13
  • modelHitZ: value14

The other values are only filled if there is a collision, they contain nil otherwise

Code Examples

shared

This example shows how you can tell what position and element the camera is looking at, up to 50 units away.

local w, h = guiGetScreenSize ()
local tx, ty, tz = getWorldFromScreenPosition ( w/2, h/2, 50 )
local px, py, pz = getCameraMatrix()
hit, x, y, z, elementHit = processLineOfSight ( px, py, pz, tx, ty, tz )
if hit then
outputChatBox ( "Looking at " .. x .. ", " .. y .. ", " .. z )
if elementHit then
outputChatBox ( "Hit element " .. getElementType(elementHit) )
end
end

See Also

World Functions