I'm new to Augmented Reality and I was going with Apple docs and WWDC videos to create my scene using Reality Composer simple blue ball that orbits around a white ball when I tap on blue ball but the tap trigger is not working when running on real device (iPhone 13) but working in Reality Composer, and here is the .rcproject
url:
class ViewController: UIViewController {
let arVi = ARView()
override func viewDidLoad() {
super.viewDidLoad()
let ar = try! orbits.loadScene()
arVi.scene.anchors.append(ar)
scannerView.addSubview(arVi)
arVi.translatesAutoresizingMaskIntoConstraints = false
arVi.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width).isActive = true
arVi.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.height).isActive = true
arVi.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
arVi.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
}
}
CodePudding user response:
There might be five possible problems:
- You're trying to play behaviors on iOS Simulator:
- Reality Composer Tap-behaviors can be run on a real device only.
- Collision boxes' interference:
- After up-scaling, collision boxes of models intersect.
- Behaviors assigned incorrectly:
- Check the Affected Objects of Trigger and Action Sequence.
- You do not follow Swift's naming convention:
- Rename lowercased enum
orbits
toOrbits
.
- Rename lowercased enum
- Try not a Custom Behavior:
- Choose
Tap & Flip
behavior, then replace its Action withOrbit
.
- Choose
CodePudding user response:
i found the issue that the ArView was added to a scannerView which was a normal UIImageView deleting that image and adding the ArVIew to the main View make it work
class ViewController: UIViewController {
let arVi = ARView()
override func viewDidLoad() {
super.viewDidLoad()
let ar = try! orbits.loadScene()
arVi.scene.anchors.append(ar)
self.view.addSubview(arVi)
arVi.translatesAutoresizingMaskIntoConstraints = false
arVi.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width).isActive = true
arVi.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.height).isActive = true
arVi.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
arVi.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
}
}