Rotate an entity with the attachments

Hi, I create an entity and add a bunch of attachments (code is based on the Diorama demo). I can rotate the entity with this:

.gesture(
            DragGesture()
                .targetedToAnyEntity()
                .onChanged { value in
                    let entity = value.entity
                    let orientation = Rotation3D(entity.orientation(relativeTo: nil))
                    let newOrientation: Rotation3D

                    if (value.location.x >= lastGestureValue) {
                        newOrientation = orientation.rotated(by: .init(angle: .degrees(0.5), axis: .y))
                    } else {
                        newOrientation = orientation.rotated(by: .init(angle: .degrees(-0.5), axis: .y))
                    }
                    entity.setOrientation(.init(newOrientation), relativeTo: nil)
                    lastGestureValue = value.location.x
                }
        )

But the attachments stay still. How can I rotate the entity AND the attachment at the same time?

Hello,

I suspect that your attachment entities are not children of the entity your are rotating in your gesture. If they were, I would expect that they would rotate with the entity.

Hi, Here is my code. I attach it with scene.addChild(Left_Hemisphere) Should I use a different rotation method? The rotation of the main entity works well. But the attachment does not move. I used this rotation code (got it from another post here https://developer.apple.com/forums/thread/748192). It works well and it rotates the entity over its axes.

    
    @State private var lastGestureValueX = CGFloat(0)
    @State private var lastGestureValueY = CGFloat(0)

    
    
    var body: some View {
        RealityView { content, attachments in
            // Add the initial RealityKit content
            if let scene = try? await Entity(named: "Immersive", in: realityKitContentBundle) {
                content.add(scene)
                scene.generateCollisionShapes (recursive: true)
                scene.components.set(InputTargetComponent())
                if let Left_Hemisphere = attachments.entity(for: "Left_Hemisphere") {
                    //4. Position the Attachment and add it to the RealityViewContent
                    Left_Hemisphere.position = [-0.5, 1, 0]
                    scene.addChild(Left_Hemisphere)
                }
            }
        } attachments: {
            Attachment(id: "Left_Hemisphere") {
                //2. Define the SwiftUI View
                Text("Left_Hemisphere")
                    .font(.extraLargeTitle)
                    .padding()
                    .glassBackgroundEffect()
            }
        }
       .gesture(
                    DragGesture()
                                .targetedToAnyEntity()
                                .onChanged { value in
                                    let entity = value.entity
                                    var orientation = Rotation3D(entity.orientation(relativeTo: nil))
                                    var newOrientation: Rotation3D
                                    if (value.location.x >= lastGestureValueX) {
                                        newOrientation = orientation.rotated(by: .init(angle: .degrees(0.5), axis: .y))
                                    } else {
                                        newOrientation = orientation.rotated(by: .init(angle: .degrees(-0.5), axis: .y))
                                    }
                                    entity.setOrientation(.init(newOrientation), relativeTo: nil)
                                    lastGestureValueX = value.location.x
                                    orientation = Rotation3D(entity.orientation(relativeTo: nil))
                                    if (value.location.y >= lastGestureValueY) {
                                        newOrientation = orientation.rotated(by: .init(angle: .degrees(0.5), axis: .x))
                                    } else {
                                        newOrientation = orientation.rotated(by: .init(angle: .degrees(-0.5), axis: .x))
                                    }
                                    entity.setOrientation(.init(newOrientation), relativeTo: nil)
                                    lastGestureValueY = value.location.y
                                 }
                )
    }
}
Rotate an entity with the attachments
 
 
Q