Hi, I have my camera which changes position with the player/user.
I would like to instantiate a UI component (panel) in front of it at an specific moment.
I have managed to instantiate something referenced to the camera position in one of the axis, but it does not instantiate in front because the camera position and rotation changes constantly.
how can I instantiate or move something always “x” distance, in front of the camera?
cameraPositionOnReading = Camera.main.transform.forward;
var t = Camera.main.transform;
panel.transform.position = new Vector3(
t.position.x,
t.position.y,
t.position.z + UIoffset);
panel.SetActive(true);
The easiest way is to make the panel a child of camera, and set its local position a fixed distance.
Otherwise heres a function i use, called from Update, it includes an option to keep the object a fixed height off the floor, and adds a lerp to smooth any jitters.
Actually I am not sure I explained myself properly, Once this is instantiated in front of the camera.
I don’ t need it to move with the camera, It’s about finding/setting something in the space and make it fixed there.
That’s is the reason why I cannot make it child of the camera. and also because otherwise I cannot interact with the cursor (hololens) with it.
Thank you very much, at the end I combined a bit what you suggested.
void OnDetectionMoveAndRotate()
{
if (panel != null)
{
panel.transform.position = Camera.main.transform.position + Camera.main.transform.forward * UIoffset;
panel.transform.rotation = Camera.main.transform.rotation;
panel.SetActive(true); // to toggle the pannel use ! operator to open simple use true and close simply use false
}
}