D
D
Deathgar2018-05-22 16:39:11
Unity
Deathgar, 2018-05-22 16:39:11

How to rotate an object relative to the camera (axis)? How do I know which axis I'm looking at with the camera?

There is a little code:

void Update()
    {
        if (Input.GetMouseButton(0))
        {
          
           if(global.ChoosenGameObject != null)
            {
                global.ChoosenGameObject.transform.Rotate( 0f, speed * Input.GetAxis("Horizontal") * -1f, 0f, Space.World);
                global.ChoosenGameObject.transform.Rotate(0f, 0f, speed * Input.GetAxis("Vertical"), Space.World);
            }
        }
    }

global.ChoosenGameObject is just a gameObject
I rotate global.ChoosenGameObject with the mouse. I approach the object with the camera from different sides. Rotation along Y goes without problems, no matter which side I approach with the camera. But there is a problem with X and Z. Because If I rotate only in X or Z, then from whichever side I approach, the object will only rotate in X or Z.
How do I know which axis I am looking at with the camera?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question