Transform Entities in RealityView?

So I have a RealityView with an Entity (from my bundle) being rendered in it like so:

struct ImmersiveView: View {
    var body: some View {
        RealityView { content in
            // Add the initial RealityKit content
            if let entity = try? await Entity(named: "MyContent", in: realityKitContentBundle) {
                content.add(entity)
            }
        }
    }
}

Is it possible to programatically transform the entity? Specifically I want to (1) translate it horizontally in space, eg 1m to the right, and (2) rotate it 90°. I've been looking through the docs and haven't found the way to do this, but I fear I'm not too comfortable with Apple docs quite yet.

Thanks in advance!

Hello,

Yes this is possible, for example, you might do something like this:

            if let entity = try? await Entity(named: "MyContent", in: nil) {
                // translate 1 meter to the right.
                entity.position.x += 1
                // rotate 90 degrees. import Spatial to get Rotation3D.
                let orientation = Rotation3D(entity.orientation)
                let newOrientation = orientation.rotated(by: .init(angle: .degrees(90), axis: .y))
                entity.orientation = .init(newOrientation)
                
                content.add(entity)
            }

Note that the Spatial framework contains lots of convenience methods related to 3D transformations, and is required for the snippet I put above to compile.

Transform Entities in RealityView?
 
 
Q