Performs collision tests (such as ray casts) in one or more world. See Physics.createGlobalProbe(), Physics.createRootProbe(), WorldComponent.createProbe().

// 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);
}
});
});
interface Probe {
    debugDrawEnabled: boolean;
    filter: Filter;
    getTypeName(): string;
    isOfType(type: string): boolean;
    isSame(other: ScriptObject): boolean;
    rayCast(start: vec3, end: vec3, hitCB: ((hit: RayCastHit) => void)): void;
    rayCastAll(start: vec3, end: vec3, hitCB: ((hit: RayCastHit[]) => void)): void;
    shapeCast(shape: Shape, start: vec3, startRot: quat, end: vec3, endRot: quat, hitCB: ((hit: RayCastHit) => void)): void;
    shapeCastAll(shape: Shape, start: vec3, startRot: quat, end: vec3, endRot: quat, hitCB: ((hit: RayCastHit[]) => void)): void;
    sphereCast(radius: number, start: vec3, end: vec3, hitCB: ((hit: RayCastHit) => void)): void;
    sphereCastAll(radius: number, start: vec3, end: vec3, hitCB: ((hit: RayCastHit[]) => void)): void;
}

Hierarchy (view full)

Properties

debugDrawEnabled: boolean

Show intersection tests with debug-draw.

filter: Filter

Filter settings applied to intersection tests.

Methods

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

    Parameters

    • type: string

    Returns boolean

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

    Parameters

    Returns boolean

  • 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

    Returns 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

    Returns 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

    Returns 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

    Returns 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

    Returns 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

    Returns void