Why Does My Cube Player rotate 180 degrees when I start My game?
I followed the beginner space shooter tutorial and I wanted to adjust the project to have my own assets. I want the Player to be a flat image (and probably the asteroids too) so I made a cube and used an image as the texture. So far everything is working still as far as game functionality but my image is showing up 'flipped' both horizontally and vertically. I want my cube to be rotated 180 degrees. I tried changing the rotation y and z to 180 in the inspector and that makes the game and scene view look correct but when I start the game those changes to the inspector default back to 0.
Basically I need to rotate my 'cube' player 180 degrees to face the oncoming asteroids.
If someone could help me that would be awesome!
Thanks!
Answer by Vice_Versa · Sep 04, 2015 at 09:29 PM
hmm. from the sound of it, you have something in one of your scripts that are setting the players rotation to 0. what you can do through script is float myY = 180f; float myZ = 180f;
void Start()
{
Vector3 temp = transform.rotation.eulerAngles;
temp.y = myY;
temp.z = myZ;
transform.rotation = Quaternion.Euler(temp);
Answer by dhaas · Sep 08, 2015 at 02:00 PM
@Vice_Versa Thanks so much for your response. I'm not sure I know where to put this exactly. I tried to just add that code above my void update on my PlayerController script and close the bracket and added two int variables myY and myZ and set them to 180 but that didn't work. I feel like there may be a simpler way to do change the rotation but I'm not sure how.
Here is what my code looks like now for the player..
And then here it is with your code I tried to add. Let me know if you know what I'm doing wrong! Thanks so much!
I found the solve here:
http://answers.unity3d.com/questions/278881/how-to-change-rotation-through-script.html
Your answer
Follow this Question
Related Questions
How do I stop my cube from rotating when it hits the ground ? 0 Answers
Why is my Player game object not rotating with mouse movement in 'Survival Shooter' unity project 10 Answers
My script does not work each time i enter Unity unless i add it to the object again. any solutions? 0 Answers
[C#] Rotate player to camera forward look 0 Answers
How can I make the camera not overreach a limit of rotation one axis. 0 Answers