- Home /
How to position and rotate an object based on which way the camera is facing
Hi,
I want to rotate and position a floating menu that does not move when the character moves. I have one that works pretty well, but the only problem is that it does not take into account which direction the character is facing. It just pops up based on the character position plus an offset. Here is the code I have so far:
void Update () {
if(Input.GetButtonDown("Fire1"))
{
playerTransform.position = player.transform.position;
if(canvas.GetComponent<Canvas>().enabled == true)
{
canvas.GetComponent<Canvas>().enabled = false;
playerTransform.position = player.transform.position;
return;
}
else
{
canvas.transform.position = player.transform.position + menuOffset.position;
canvas.GetComponent<Canvas>().enabled = true;
}
}
if (player.transform.position != playerTransform.position) {
canvas.GetComponent<Canvas>().enabled = false;
}
}
How would I take into account the rotation of the camera so the menu appears in front of you no matter which direction you're looking? One more thing: I don't want the menu to take into account x or z rotation, but the y rotation.
Thanks!
Your answer
Follow this Question
Related Questions
How to Rotate 3D Object using Accelerometer? 1 Answer
i need to rotate cube in z axis or x axis one direction at time 0 Answers
How can I make player rotation control camera's x rotation and mouse control it's y rotation? 1 Answer
I want a camera to be a child of my player but not to follow it's rotation 2 Answers
Converting 3D Rotation to 2D Rotation 0 Answers