Hey LT13 -
I had to do something similar recently, and I solved it by checking the distance from the camera to my entity in the session delegate didUpdate function, and setting the scale based on the distance. Please consider the following example below:
func session(_ session: ARSession, didUpdate frame: ARFrame) {
for entity in self.arView.scene.anchors {
if case let AnchoringComponent.Target.world(transform) = entity.anchoring.target {
let distance = distance(transform.columns.3, frame.camera.transform.columns.3)
entity.scale = .one * (4 * sqrtf(distance))
}
}
}
You can change the entity.scale formula to work however you'd like. For me, it sets an initial scale for the entity and will scale it relative to the distance between the camera and the entity.
Topic:
Spatial Computing
SubTopic:
ARKit
Tags: