- Home /
 
How can i rotate object by pressing on key R and keep object facing to me my self ?
This is a screenshot of what i mean facing to me my self. This is when i'm running the game before pressing R the object i want to rotate name NAVI is facing/looking at me my self.
me my self meaning RigidBodyFPSController (1)
I don't want the NAVI object to look the RigidBodyFPSController (1)/MainCamera facing direction but to be facing all the time to my my self to the place.

And this is a screenshot showing the object Hierarchy and inspector. The script is attached to the MainCamera. The MainCamera is child of the RigidBodyFPSController (1)
And NAVI the object i want to rotate is child of the MainCamera.

My main goal is very simple. I Want when pressing on R to rotate the NAVI object either looking facing forward or backward. forward look to the front i mean and backward look at the player.
In the top of the script:
 public float rotationSpeed;
 private float x;
 private int damping = 2;
 
               In Update:
 if (Input.GetKey(KeyCode.R))
         {
             x += Time.deltaTime * rotationSpeed;
             objectToScale.transform.rotation = Quaternion.Euler(0, 0, x);
         }
         var lookPos = transform.position - objectToScale.transform.position;
         lookPos.y = 0;
         var rotation = Quaternion.LookRotation(lookPos);
         objectToScale.transform.rotation = Quaternion.Slerp(objectToScale.transform.rotation, rotation, Time.deltaTime * damping);
 
               I have not decided yet what i want to do in the end but i want to know how to rotate the object on Z axis but to keep the object facing forward or backward.
Your answer