WorldRaycast.raycastPlanes
FunctionPerforms 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.
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
| Parameter | Type | Description |
|---|---|---|
from | vec3 | Starting point of the ray in world space coordinates |
to | vec3 | Ending point of the ray in world space coordinates |
Returns
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
Worldtracking 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);
}
});