physicsOrigin
The entity that defines the origin of the scene’s physics simulation.
Declaration
@MainActor @preconcurrency var physicsOrigin: Entity? { get set }Mentioned in
Discussion
By default, the scene’s origin acts as the origin for physics calculations. Set the physicsOrigin to choose a particular entity within the scene to act as the origin instead.
Here are the steps to do that:
Add a new entity to the scene that tracks the ARKit anchor position.
Set
physicsOriginto the entity to indicate that this entity’s transform determines the origin of the physics simulation.Optionally, parent the Jenga blocks to the anchor entity. This way the Jenga blocks update automatically when the anchor position changes.
Example:
// Define your anchor entity and add it to the scene.
let myAnchor = AnchorEntity(.image(group: "References", name: "GameImage"))
scene.addAnchor(myAnchor)
// Set myAnchor as the origin of the physics simulation.
arView.physicsOrigin = myAnchor
// Add the simulated blocks to the anchor.
myAnchor.addChild(block0)
myAnchor.addChild(block1)
// ...Using this setup, RealityKit simulates all forces, velocities, etc. relative to myAnchor. Moving the anchor will not affect the simulation.
For more information, see Handling different-sized objects in physics simulations.