[0.8.9][NK] WorldQuery

johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
edited December 2015 in Modding Tutorials
WorldQueries are used to detect objects placed in the world.

Uses:
  • Detecting if 2 objects overlap
  • Growable objects use it to detect if there is enough space to plant
  • AICharacters use it to detect threats/targets
  • Right click placement of torches detects hit position
  • Tools use it to detect the material type of voxels
  • Projectiles use it to detect hits

WorldQueries:

Data types

Input types:
ignoreObjects - array of objects to ignore
layerMask - LayerMask

QueryHit:
	normal				vec3
contact vec3
queryPosition vec3
distance float
matID int
internalType int
body RigidbodyComponent
gameobject GameObject
Return types:
Boolean - true/false
QueryHit - table (QueryHit)
Array[QueryHit] - array of QueryHits
Array[GameObject] - array of GameObjects

QueryResults limit

HAVOKMAXQUERYRESULTS is a variable set in [TUG]/Config/user_config.txt, by default it's set to 10.
This value will limit the amount of hits cast/sweep world queries return.

To change the limit you can use NKSetMaxQueryResults.

Setting max query results limit:
Eternus.PhysicsWorld:NKSetMaxQueryResults(100)
Resetting max query results limit:
Eternus.PhysicsWorld:NKResetMaxQueryResults()
Important: ALWAYS reset the max query results limit once you have finished all of your queries!

RayCast


RayCast casts a ray from origin in direction limited by distance.

RayCastCheck (check for hit)
local ret = EternusEngine.Physics.RayCastCheck(
origin, -- origin of the ray (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Boolean

RayCastCollect (collect 1st hit)
local ret = EternusEngine.Physics.RayCastCollect(
origin, -- origin of the ray (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: QueryHit

RayCastCollectAll (collect all hits, limited by HAVOKMAXQUERYRESULTS)
local ret = EternusEngine.Physics.RayCastCollectAll(
origin, -- origin of the ray (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Array[QueryHit]


LineCast


LineCast casts a line from position to position

RayCastCheck (check for hit)
local ret = EternusEngine.Physics.LineCastCheck(
from, -- start of the line (vec3)
to, -- end of the line (vec3)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Boolean

RayCastCollect (collect 1st hit)
local ret = EternusEngine.Physics.LineCastCollect(
from, -- start of the line (vec3)
to, -- end of the line (vec3)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: QueryHit

RayCastCollectAll (collect all hits, limited by HAVOKMAXQUERYRESULTS)
local ret = EternusEngine.Physics.LineCastCollectAll(
from, -- start of the line (vec3)
to, -- end of the line (vec3)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Array[QueryHit]


SphereSweep


SphereSweep sweeps a sphere from origin in direction limited by distance

SphereSweepCheck (check for hit)
local ret = EternusEngine.Physics.SphereSweepCheck(
radius, -- radius of the sphere (float)
origin, -- origin of the sphere sweep (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Boolean

SphereSweepCollect (collect 1st hit)
local ret = EternusEngine.Physics.SphereSweepCollect(
radius, -- radius of the sphere (float)
origin, -- origin of the sphere sweep (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: QueryHit

SphereSweepCollectAll (collect all hits, limited by HAVOKMAXQUERYRESULTS)
local ret = EternusEngine.Physics.SphereSweepCollectAll(
radius, -- radius of the sphere (float)
origin, -- origin of the sphere sweep (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Array[QueryHit]


AABBSweep


AABBSweep sweeps AABB from origin in direction limited by distance

AABBSweepCheck (check for hit)
local ret = EternusEngine.Physics.AABBSweepCheck(
min, -- min position of the AABB
max, -- max position of the AABB
origin, -- origin of the AABB sweep (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Boolean

AABBSweepCollect (collect 1st hit)
local ret = EternusEngine.Physics.AABBSweepCollect(
min, -- min position of the AABB
max, -- max position of the AABB
origin, -- origin of the AABB sweep (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: QueryHit

AABBSweepCollectAll (collect all hits, limited by HAVOKMAXQUERYRESULTS)
local ret = EternusEngine.Physics.AABBSweepCollectAll(
min, -- min position of the AABB
max, -- max position of the AABB
origin, -- origin of the AABB sweep (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Array[QueryHit]


ObjectSweep


ObjectSweep sweeps an object from origin in direction limited by distance

ObjectSweepCheck (check for hit)
local ret = EternusEngine.Physics.ObjectSweepCheck(
object, -- object to use for the sweep
origin, -- origin of the Object sweep (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Boolean

ObjectSweepCollect (collect 1st hit)
local ret = EternusEngine.Physics.ObjectSweepCollect(
object, -- object to use for the sweep
origin, -- origin of the Object sweep (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: QueryHit

ObjectSweepCollectAll (collect all hits, limited by HAVOKMAXQUERYRESULTS)
local ret = EternusEngine.Physics.ObjectSweepCollectAll(
object, -- object to use for the sweep
origin, -- origin of the Object sweep (vec3)
direction, -- direction (vec3)
distance, -- distance (float)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
startFraction, -- [optional] fraction start range (0.0-1.0)
endFraction -- [optional] fraction end range (0.0-1.0)
)
Returns: Array[QueryHit]


SphereOverlap


SphereOverlap collects all objects overlapping a sphere

SphereOverlapCheck (check for overlap)
local ret = EternusEngine.Physics.SphereOverlapCheck(
radius, -- radius of the sphere (float)
origin, -- position of the sphere overlap check (vec3)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Boolean

SphereOverlapCollect (collect all objects)
local ret = EternusEngine.Physics.SphereOverlapCollect(
radius, -- radius of the sphere (float)
origin, -- position of the sphere overlap check (vec3)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Array[GameObject]


AABBOverlap


AABBOverlap collects all objects overlapping a AABB

AABBOverlapCheck (check for overlap)
local ret = EternusEngine.Physics.AABBOverlapCheck(
min, -- min position of the AABB
max, -- max position of the AABB
origin, -- position of the AABB overlap check (vec3)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Boolean

AABBOverlapCollect (collect all objects)
local ret = EternusEngine.Physics.AABBOverlapCollect(
min, -- min position of the AABB
max, -- max position of the AABB
origin, -- position of the AABB overlap check (vec3)
ignoreObjects, -- [optional] array of ignored objects
layerMask -- [optional] layer mask
)
Returns: Array[GameObject]


ObjectsOverlap


ObjectsOverlap checks if objectA overlaps with objectB

ObjectsOverlap (check for overlap)
local ret = EternusEngine.Physics.ObjectsOverlap(
objectA, -- Object A
objectB -- Object B
)
Returns: Boolean
My Blog
jc.png
  yt.png  t.png  
Sign In or Register to comment.