Search code examples
swiftaugmented-realityrealitykit

Interact with several ModelEntities


Is there an easy way to interact with several ModelEntities in RealityKit at the same time? for example rotate two ModelEntities with one multi-touch gesture.


Solution

  • Of course you can. Just create a parent entity for two or more children.

    let parentEntity = Entity()
    parentEntity.addChild(childEntity01)
    parentEntity.addChild(childEntity02)
        
    arView.installGestures([.all], for: parentEntity as! Entity & HasCollision)
    

    P. S.

    Also, this post will show you how raycasting works in conjunction with RealityKit gestures.