Skip to content

physics.TraceMultiple

Jérôme Leclercq edited this page Dec 8, 2020 · 2 revisions

API: physics.TraceMultiple

Description:

Trace a ray between two positions and calls a function for every hit entity.

Prototype:

physics.TraceMultiple(layer: integer, startPos: vec2, endPos: vec2, callback: function)

Parameters:

  1. layer: The layer to query.
  2. startPos: The starting position of the ray.
  3. endPos: The end position of the ray.
  4. callback: The callback that will be called for every entity with a table containing data about the intersection.
    Fields:
    • fraction: number : A number ranging from 0 to 1 indicating how far the ray travelled before hitting the entity.
    • hitPos: vec2 : The hit position.
    • hitNormal: vec2 : The hit position.
    • hitEntity: Entity : The hit entity.

Remarks:

  1. There is not particular order in which the callback will be called, if you want to have code executed for every entity a particular order, for example nearest to furthest you have to store all entities in a table and order it by fraction once this function returns and iterate from there.
  2. If you're only interested with the nearest hit, consider using the more efficient physics.Trace function.

Clone this wiki locally