Search code examples
swiftarkitrealitykit

How to keep a plane in place as the phone moves?


I am creating a Plane with a VideoMaterial and placing it over a recognized image. The anchor for the plane is created like this:

let anchor = AnchorEntity(world: imageAnchor.transform)

And that works fine for the initial location. But I want it to stay in place as I move the phone around, and it doesn't. It doesn't quite follow the phone, either, but it moves in the same general direction.

I think the fix for this is to keep updating the anchor's transform in didUpdate, but to what? I only have the current transform of the imageAnchor and no way to convert it to world coordinates. I tried using it unconverted and the plane ended in an entirely wrong place.


Solution

  • Tracking native and ARKit anchors in RealityKit


    Native RealityKit's case image(group: String, name: String) automatically tracks its target (image).

    AnchorEntity(.image(group: "ARGroup", name: "myImage"))
    

    If you prefer to track ARKit's ARImageAnchor, then use session(_:didUpdate:) delegate method.

    AnchorEntity(anchor: arImageAnchor)