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

instead of local scale flip, using transform rotate HELP

Discussion in '2D' started by ianmcelvain, Nov 6, 2015.

  1. ianmcelvain

    ianmcelvain

    Joined:
    Jan 28, 2014
    Posts:
    37
    This is the function i use for my character to turn in my project but instead of flipping the local scale can someone show me transform.rotate script for walking in a 2d game?

    I really need rotate more than local scale for all the children attached to the player.
     
  2. Prototypetheta

    Prototypetheta

    Joined:
    May 7, 2015
    Posts:
    122
    Code (CSharp):
    1. void Flip()
    2. {
    3. facingRight = !facingRight;
    4. Vector3 theFlip = new Vector3 (transform.eulerAngles.x, transform.eulerAngles.y + 180, transform.eulerAngles.z);
    5.  
    6. transform.eulerAngles = theFlip;
    7. }
    Untested, but I think this will do what you are after. In theory this should rotate the entire object around the y axis.
     
  3. ianmcelvain

    ianmcelvain

    Joined:
    Jan 28, 2014
    Posts:
    37
    Indeed it should work. I tried this about an hour ago and once i tested and tested and still failed i just took a break

    I did end up fixing the problem just now, i worked around the character and got my children functions to work with the characters flip but man sometimes Unity's commands (especially with 2d) make it more complicated than it has to be.