Skip to main content

Probe

Class

Performs collision tests (such as ray casts) in one or more world.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v164

Index

Example

// Given an object with a BodyComponent
// If the object intersects with the ray described
// by rayStart and rayEnd, print a message.

var rayStart = new vec3(0.0, -100.0, 0.0);
var rayEnd = new vec3(0.0, 100.0, 0.0);

// Create a probe to raycast through all worlds.
var globalProbe = Physics.createGlobalProbe();
globalProbe.rayCast(rayStart, rayEnd, function (hit) {
if (hit) {
print("Raycast hit: " + hit.collider.getSceneObject().name);
}
});

// Create a probe to raycast through only the implicit root world.
var rootProbe = Physics.createRootProbe();
rootProbe.rayCast(rayStart, rayEnd, function (hit) {
if (hit) {
print("Raycast hit all: " + hit.collider.getSceneObject().name);
}
});
// On Tap, raycast through the scene at the tapped position and print out a message for each object hit.

// @input Component.Camera camera

var cameraTransform = script.camera.getTransform();
var camera = script.camera;

script.createEvent("TapEvent").bind(function(touchArgs) {
var touchPos = touchArgs.getTapPosition();
var nearPos = camera.screenSpaceToWorldSpace(touchPos, 0);
var farPos = camera.screenSpaceToWorldSpace(touchPos, camera.far - camera.near);
Physics.createGlobalProbe().rayCastAll(nearPos, farPos, function(hitResults) {
print("Hit " + hitResults.length + " objects:")
for(var i=0; i<hitResults.length; i++) {
var hit = hitResults[i];
print(hit.collider.getSceneObject().name + " at " + hit.position);
}
});
});

Extends

Properties

debugDrawEnabled

debugDrawEnabled: boolean

Show intersection tests with debug-draw.

Since

Lens Scripting Version 164

Default Value

false

filter

filter: Filter

Filter settings applied to intersection tests.

Since

Lens Scripting Version 164

Default Value

null

Methods

getTypeName()

static getTypeName(): TypeName<Probe>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<Probe>

Since

Lens Scripting Version 164

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


rayCast()

rayCast(start, end, hitCB): void

Returns (via callback) the nearest intersection in any world. If there is no hit, the callback is called with a null hit argument. Ray casts are performed after simulation update, which occurs after script Update but prior to LateUpdate.

Parameters

ParameterType
startvec3
endvec3
hitCB(hit?) => void

Returns

void

Since

Lens Scripting Version 164


rayCastAll()

rayCastAll(start, end, hitCB): void

Returns (via callback) all intersections in every world. The callback receives an array of hits, in order of nearest to farthest. If there were no hits, the array length is 0. Ray casts are performed after simulation update, which occurs after script Update but prior to LateUpdate.

Parameters

ParameterType
startvec3
endvec3
hitCB(hit) => void

Returns

void

Since

Lens Scripting Version 164


rayCastAllSync()

rayCastAllSync(start, end): RayCastHit[]

Returns all intersections synchronously, in order of nearest to farthest. If there were no hits, the array length is 0.

See Probe#rayCastSync for timing considerations.

Parameters

ParameterType
startvec3
endvec3

Returns

RayCastHit[]

Since

Lens Scripting Version 358


rayCastSync()

rayCastSync(start, end): RayCastHit

Returns the nearest intersection synchronously. If there is no hit, returns null. Unlike rayCast(), the result is returned directly without a callback.

For current-frame results, call this in LateUpdate. The physics simulation step runs between Update and LateUpdate, so calling in Update, onStart, or event handlers will return results based on the previous frame's physics state.

Note: dynamically scaled or created physics objects may not be reflected in results until the next physics step has processed them.

Parameters

ParameterType
startvec3
endvec3

Returns

RayCastHit

Since

Lens Scripting Version 358


shapeCast()

shapeCast(shape, start, startRot, end, endRot, hitCB): void

Like rayCast(), but sweeps a sphere from start to end positions. This is shorthand for calling shapeCast() with a SphereShape. Returns (via callback) the nearest intersection. If there is no hit, the callback is called with a null hit argument. Ray casts are performed after simulation update, which occurs after script Update but prior to LateUpdate.

Parameters

ParameterType
shapeShape
startvec3
startRotquat
endvec3
endRotquat
hitCB(hit?) => void

Returns

void

Since

Lens Scripting Version 181


shapeCastAll()

shapeCastAll(shape, start, startRot, end, endRot, hitCB): void

Like rayCastAll(), but sweeps a shape from start to end transforms (expressed as position and rotation). The provided shape can be created with one of the Shape.create*() functions, or referenced from a Physics.ColliderComponent. Does not support MeshShape, and will throw an exception if attempted. Returns (via callback) all intersections. The callback receives an array of hits, in order of nearest to farthest. If there were no hits, the array length is 0. Ray casts are performed after simulation update, which occurs after script Update but prior to LateUpdate.

Parameters

ParameterType
shapeShape
startvec3
startRotquat
endvec3
endRotquat
hitCB(hit) => void

Returns

void

Since

Lens Scripting Version 181


shapeCastAllSync()

shapeCastAllSync(shape, start, startRot, end, endRot): RayCastHit[]

Like rayCastAllSync(), but sweeps a shape from start to end transforms. Returns all intersections synchronously. Does not support MeshShape, and will throw an exception if attempted.

See Probe#rayCastSync for timing considerations.

Parameters

ParameterType
shapeShape
startvec3
startRotquat
endvec3
endRotquat

Returns

RayCastHit[]

Since

Lens Scripting Version 358


shapeCastSync()

shapeCastSync(shape, start, startRot, end, endRot): RayCastHit

Like rayCastSync(), but sweeps a shape from start to end transforms. Returns the nearest intersection synchronously, or null if there is no hit. Does not support MeshShape, and will throw an exception if attempted.

See Probe#rayCastSync for timing considerations.

Parameters

ParameterType
shapeShape
startvec3
startRotquat
endvec3
endRotquat

Returns

RayCastHit

Since

Lens Scripting Version 358


sphereCast()

sphereCast(radius, start, end, hitCB): void

Like rayCast(), but sweeps a sphere from start to end positions. This is shorthand for calling shapeCast() with a SphereShape. Returns (via callback) the nearest intersection. If there is no hit, the callback is called with a null hit argument. Ray casts are performed after simulation update, which occurs after script Update but prior to LateUpdate.

Parameters

ParameterType
radiusnumber
startvec3
endvec3
hitCB(hit?) => void

Returns

void

Since

Lens Scripting Version 181


sphereCastAll()

sphereCastAll(radius, start, end, hitCB): void

Like rayCastAll(), but sweeps a sphere from start to end positions. This is shorthand for calling shapeCastAll() with a SphereShape. Returns (via callback) all intersections. The callback receives an array of hits, in order of nearest to farthest. If there were no hits, the array length is 0. Ray casts are performed after simulation update, which occurs after script Update but prior to LateUpdate.

Parameters

ParameterType
radiusnumber
startvec3
endvec3
hitCB(hit) => void

Returns

void

Since

Lens Scripting Version 181


sphereCastAllSync()

sphereCastAllSync(radius, start, end): RayCastHit[]

Like rayCastAllSync(), but sweeps a sphere from start to end positions. Returns all intersections synchronously.

See Probe#rayCastSync for timing considerations.

Parameters

ParameterType
radiusnumber
startvec3
endvec3

Returns

RayCastHit[]

Since

Lens Scripting Version 358


sphereCastSync()

sphereCastSync(radius, start, end): RayCastHit

Like rayCastSync(), but sweeps a sphere from start to end positions. Returns the nearest intersection synchronously, or null if there is no hit.

See Probe#rayCastSync for timing considerations.

Parameters

ParameterType
radiusnumber
startvec3
endvec3

Returns

RayCastHit

Since

Lens Scripting Version 358

See also