I’m trying to make an entity hover in the same spot in front of the camera regardless of how I move the device and I’m not succeeding. I figure that I want to rotate around y (for lateral movement - yaw) and x (for vertical panning - pitch).
I’m getting the camera rotation from the ARCamera:
let distance: Float = 2 // distance in front of camera
let euler = camera.eulerAngles
let yaw = euler.y + .pi
let x = sin(yaw) * distance
let z = cos(yaw) * distance
let translation = SIMD3<Float>(x, 1, z)
let transform = Transform(scale: .one,
rotation: simd_quatf(),
translation: translation)
entity.transform = transform
First of all I’m not clear on why I needed to rotate by .pi
keep the entity in front of the camera. Am I correct in thinking that the camera’s transform is initialized to wherever the camera is initially pointing and therefore the entity should be in front of the camera if the camera hasn’t moved?
Secondly, this all fails if I try to perform a similar operation around the x axis instead:
let pitch = euler.x + .pi
let y = sin(pitch) * distance
let z = cos(pitch) * distance
let translation = SIMD3<Float>(1, y, z)
Clearly I’m confused about what I’m doing here. Can someone straighten me out? Thanks