Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Transform.Rotation

Discussion in 'Scripting' started by Geniusme56, Feb 26, 2023.

  1. Geniusme56

    Geniusme56

    Joined:
    Aug 21, 2021
    Posts:
    55
    This I feel like is a very simple solution, but I can't seem to figure it out. I'm new to 3d and maybe it's different from unity 2d, but whenever I try setting the y rotation to any number, it just automatically sets it to 180. Thanks in advance.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    We know rotation works so it must be something on your side, but you've given zero information above.

    You may wish to review the docs for the differences between Transform.Rotate() versus directly setting a rotation by assigning it to the transform.rotation property.

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried
    - what you expected to happen
    - what actually happened, especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)

    You may edit your post above.

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
  3. Geniusme56

    Geniusme56

    Joined:
    Aug 21, 2021
    Posts:
    55
    I want for my character to move horizontally and vertically, so he won't ever move diagonally. So, if I press "A", he will face left and move left, and if I press "D" he will face right and move right and etc. I have tried
    Code (CSharp):
    1.  if (Input.GetKey(KeyCode.A))
    2.         {
    3.             transform.localRotation = new Quaternion(0, -90, 0, 0);
    4.         }
    but it sets the y rotation to 180 degrees. There are no errors, and the only two rotations that work are 0 and 180.
     
  4. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,903
  5. Geniusme56

    Geniusme56

    Joined:
    Aug 21, 2021
    Posts:
    55
    That worked! Thank you!