Sitemap

Ray Casting in RealityKit

Ray casting is the new hit testing in ARKit 3

1 min readAug 18, 2019

This is part of my RealityKit Snippets collection of short code examples for getting things done in RealityKit.

About Ray Casting & Applications

  • Convert from 2D screen space to 3D surfaces in world space
  • Place content on a surface directly in front of the camera or where the user taps the screen

Simple Ray Cast Example

Make a ray cast from the center of the screen.

Tracked Ray Cast Example

ARKit will keep refining the ray cast as it learns more about detected surfaces.

Modifications

  1. Ray cast origin (from: CGPoint)
    Change this parameter to any point on the screen. Combine ray casting with a gesture recognizer to allow users to place content on a selected surface
  2. Plane type (allowing: ARRaycastQuery.Target)
    Select which type of surfaces you want to search for. This parameter allows you to limit the search to existing planes or estimated planes. Check out Apple’s documentation for details about each target case.
  3. Plane orientation (alignment: ARRaycastQuery.TargetAlignment)
    Select horizontal, vertical, or any planes.

--

--

Ethan Saadia
Ethan Saadia

Written by Ethan Saadia

Founder at PhotoCatch. Developing 3D content creation tools for everyone. 2x  WWDC Scholar. Developer, Engineer, and Entrepreneur.

Responses (1)