How to rotate 3d usdz model in tapped direction with realityKit?

Viewed 89

I am able to get the world transform from raycasting using the tapped 2d point, now suppose the 3d usdz model is facing completely opposite direction and is placed on an image using image tracking, I have to dynamically rotate that model so that its face points towards the direction in which user has tapped.

Note:- The angle should be calculated dynamically based on the rayCasting result.

1 Answers

Set the rotation of the model so that it would rotate .pi radians about the y axis (yaw).

let rotationTransform = Transform.init(pitch: 0, yaw: .pi, roll: 0)
let newTransform = simd_mul(modelInitialTransform, rotationTransform.matrix)
model.move(to: newTransform, relativeTo: nil, duration: 0.3, timingFunction: .easeInOut)
Related