WorldRaycast.hitTestPlanes
FunctionPerforms a raycast against native AR-tracked planes from a screen position.
- Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.
hitTestPlanes(
screenPos,camera):TrackedPlaneHitTestResult[]
Performs a raycast against native AR-tracked planes from a screen position. The ray starts at the camera's near plane and extends through the camera's far plane at the given screen coordinates. Works on both iOS (ARKit) and Android (ARCore).
Parameters
| Parameter | Type | Description |
|---|---|---|
screenPos | vec2 | Screen coordinates in normalized device coordinates ([0-1], [0-1]), where (0,0) is the top-left of the screen and (1,1) is the bottom-right |
camera | Camera | The Camera to use for computing the screen-to-world ray |
Returns
Array of TrackedPlaneHitTestResult objects, sorted by distance from camera (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 hitTestWorldMesh, this does not require scene reconstruction support
Example
//@input Component.DeviceTracking deviceTracking
//@input Component.Camera camera
script.deviceTracking.worldOptions.nativePlaneTrackingType = NativePlaneTrackingType.Horizontal;
script.deviceTracking.requestDeviceTrackingMode(DeviceTrackingMode.World);
script.createEvent("TapEvent").bind(function (eventData) {
const screenPos = eventData.getTapPosition();
const results = WorldRaycast.hitTestPlanes(screenPos, script.camera);
if (results.length > 0) {
print("Hit plane at: " + results[0].position);
}
});