- Home /
 
 
               Question by 
               MeteoSerpent101 · Jan 11, 2019 at 03:31 AM · 
                scripting problem2d gamebeginneraxisy-axis  
              
 
              How to set y rotation axis to 90 on 2d project, always, forever
I am trying to create a top down 2d shooter and slowly realizing that Unity was only considering 2d to be used for platformers. Anyways, I'm trying to set the y-axis rotation to 90, however, my script interferes with the y-axis so it still rotates when I don't want it to. Here's my script for the character controller: `
 public float speed;
 public int health = 10;
 private Text text;
 private Rigidbody2D rb;
 private Vector2 moveVelocity;
 public Joystick stickOfHappiness;
 public float rotateSpeed;
 // Use this for initialization
 void Start () {
     rb = GetComponent<Rigidbody2D> ();
     text = GameObject.FindGameObjectWithTag ("Text").GetComponent<Text> ();
 }
 // Update is called once per frame
 void Update () {
     
     if (rb.velocity != Vector2.zero)
     {
         transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(new Vector2(rb.velocity.y, -rb.velocity.x)), Time.deltaTime * rotateSpeed);
     }
     if (health <= 0) {
         
         SceneManager.LoadScene("Main");
     }
     Vector2 moveInput = new Vector2 (stickOfHappiness.Horizontal, stickOfHappiness.Vertical);
     rb.velocity = moveInput.normalized * speed;
     text.text = "Health: " + health;
 }
 
               I'm using a virtual joystick if your curious.
               Comment
              
 
               
              Answer by aardappel156 · Jan 11, 2019 at 06:36 PM
You can add a rigidbody2D to your player and then freeze/constraint the y rotation!
There is no option for Y rotation under 2D rigid bodies. Interesting that if you use a (3D) Ridigbody, you are allowed to use all constraints.
Your answer