Skip to main content

WorldRaycast.hitTestPlanes

Function

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

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • 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

ParameterTypeDescription
screenPosvec2Screen 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
cameraCameraThe Camera to use for computing the screen-to-world ray

Returns

TrackedPlaneHitTestResult[]

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 World tracking 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);
}
});