-
-
Notifications
You must be signed in to change notification settings - Fork 10
physics.TraceMultiple
Jérôme Leclercq edited this page Dec 8, 2020
·
2 revisions
API: physics.TraceMultiple
Trace a ray between two positions and calls a function for every hit entity.
physics.TraceMultiple(layer: integer, startPos: vec2, endPos: vec2, callback: function)
-
layer: The layer to query. -
startPos: The starting position of the ray. -
endPos: The end position of the ray. -
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.
- fraction:
- 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.
- If you're only interested with the nearest hit, consider using the more efficient physics.Trace function.