Skip to main content

WorldRaycast.raycastPlanes

Function

Performs a raycast against native AR-tracked planes along a ray from world position from to world position to.

  • 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.

raycastPlanes(from, to): TrackedPlaneHitTestResult[]

Performs a raycast against native AR-tracked planes along a ray from world position from to world position to. Works on both iOS (ARKit) and Android (ARCore).

Parameters

ParameterTypeDescription
fromvec3Starting point of the ray in world space coordinates
tovec3Ending point of the ray in world space coordinates

Returns

TrackedPlaneHitTestResult[]

Array of TrackedPlaneHitTestResult objects, sorted by distance from from (nearest first). Returns an empty array if no planes are hit.

Remarks

  • Requires plane tracking to be enabled via DeviceTracking.WorldOptions.nativePlaneTrackingType
  • Requires DeviceTracking to be in World tracking mode
  • Unlike raycastWorldMesh, this does not require scene reconstruction support

Example

//@input Component.DeviceTracking deviceTracking

script.deviceTracking.worldOptions.nativePlaneTrackingType = NativePlaneTrackingType.Horizontal;
script.deviceTracking.requestDeviceTrackingMode(DeviceTrackingMode.World);

script.createEvent("TapEvent").bind(function () {
const from = new vec3(0, 0, 0);
const to = new vec3(0, 0, -600);
const results = WorldRaycast.raycastPlanes(from, to);

if (results.length > 0) {
print("Hit plane at: " + results[0].position);
}
});