I want to create a place virtually object animation for ar app.
I want to replace the square with animation.
So I create animation by the Reality Composer and export file(.reality).
then I load this file by Xcode.
var entity: Entity?
override func viewDidLoad() {
super.viewDidLoad()
arView.debugOptions = [.showPhysics]
arView.session.delegate = self
let object = try! Entity.load(named: "object_animation")
self.entity = object
let anchor = AnchorEntity()
anchor.addChild(object)
arView.scene.addAnchor(root)
}
func session(_ session: ARSession, didUpdate frame: ARFrame) {
let bounds = self.arView.bounds
let screenCenter = CGPoint(x: bounds.midX, y: bounds.midY)
guard let query = self.arView.makeRaycastQuery(from: screenCenter, allowing: .estimatedPlane, alignment: .horizontal),
let result = self.arView.session.raycast(query).first
else {
self.entity?.isEnabled = false
return
}
self.entity?.isEnabled = true
self.entity!.transform = Transform(matrix: result.worldTransform)
}
then, I build this app, the animation object position is wrong.