1

I am rotating an entity loaded from Reality Composer with the below code. I expect that the sphere will simply rotate. However, I am left with both the new rotated entity and the old entity. Thought this would be simple.

What do I do to just rotate an entity without duplicating it?

ball?.transform.rotation = simd_quatf(angle: GLKMathDegreesToRadians(90), 
                                       axis: SIMD3(x: 0, y: 1, z: 0.5))
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
user1905842
  • 165
  • 1
  • 13

1 Answers1

5

There are two possible issues that may occur when you rotate a ball:

  • There are two balls were occasionally created in Reality Composer scene, and you rotate a parent entity (node) for both ones

  • There's a bug in your app (so we don't consider it here...)


Usually a code for rotating and scaling a model in RealityKit looks like this:

let ballAnchor: Experience.Ball = try! Experience.loadBall()

ballAnchor.ball?.orientation = simd_quatf(angle: Float.pi/4, 
                                           axis: [0, 1, 0])

ballAnchor.ball?.scale = [9, 9, 9]

arView.scene.anchors.append(ballAnchor)

Where a Ball is a public class conforming to the RealityKit.HasAnchoring protocol and containing the object ball which is actually RealityKit.Entity.

So if you wanna change an X axis position of a ball object just use:

ballAnchor.ball?.position.x = 0.5

But not like this:

ball?.position.x = 0.5
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220