Hi,
I have an app that has a 2d target/site that follows a 3d object in space. I have the 2d site following the 3d object perfectly, but the 2d site changes its z position and so the 2d site scales.
The challenge of this project is that it’s an augmented reality app, I’m using ARToolKit. So I have to get the screen position from the ARToolKit camera (which moves), then using that screen position translate them to the world position in my UI Camera. Again this is working, but the 2d object scales as it moves along the z axis, of course. But I don’t want it to scale.
Any ideas how I can stop this? Either not allow movement along the z axis but somehow still center the 2d object on the 3d object.
Or should I somehow compensate the scaling of the 2d object by how much the 2d object moves on the z axis.
Below is my code:
// targetCamera is the ARToolKit camera, and targetObject is the 3d object ARToolKit displays over the image marker
Vector3 targetScreenPos = targetCamera.WorldToScreenPoint(targetObject.transform.position);
// orbitalCamera is the camera for the 2d object. the script is attached to the 2d object, so the ‘transform’ belongs to it.
Vector3 oribitalWorldPos = obitalCamera.ScreenToWorldPoint(targetScreenPos);
transform.position = oribitalWorldPos;