- Home /
[Mobile AR] Model faces away from camera?
I have a simple AR mobile (Android) project using Vuforia and this little kitten from the asset store. By default, the transform axes of any child object are locked to the axes of the ImageTarget, so that they move together in the worldspace. I, however, would like the kitten to stand upright independent of the orientation of the target or my device.
To do this, I take the accelerometer data (Input.acceleration) and pass it through a LowPass filter (i.e. simple time average) and out comes an estimated vector that represents gravity, which I assign as the Y-axis of my kitten.
private void LateUpdate() {
transform.up = -LowPassAccelerometer().normalized;
}
This works fine; my kitten stand upright no matter what. The problem is that it faces away from the camera when I hold the phone upright. I would like it to face towards the camera.
This should be simple enough but for the life of me I can't figure it out. I've tried rotating the kitten, the target and the ARCamera by 180deg around Y-axis, but they all break the "standing upright" behavior; if I rotate the device then the target starts rotating as well. I also tried setting transform.x = -transform.x, which also causes the same weird behavior.
My question is then, why does the rotation around Y break the direction of Y? Shouldn't the two be independent? How can I induce a simple rotation of my model so that by default it faces towards the ARCamera? Seems like any model I place in the scene is by default facing away from the camera.