Search Unity

Walk issue

Discussion in '2D' started by om3, Dec 26, 2014.

  1. om3

    om3

    Joined:
    Dec 11, 2014
    Posts:
    14
    Hello,

    When my gameobject invert direction with EulerAngles method, I get inverted order layers.

    Look image, the neck.
    Code (CSharp):
    1.     void move()
    2.     {
    3.  
    4.         if(Input.GetAxis("Horizontal")>0)
    5.         {
    6.             transform.Translate(Vector2.right * speedX * Time.deltaTime);
    7.             transform.eulerAngles= new Vector2(0,0);
    8.         }
    9.  
    10.         if(Input.GetAxis("Horizontal")<0)
    11.         {
    12.             transform.Translate(Vector2.right * speedX * Time.deltaTime);
    13.             transform.eulerAngles= new Vector2(0,180);
    14.         }
    15.     }
     

    Attached Files:

    • walk.PNG
      walk.PNG
      File size:
      19.1 KB
      Views:
      799
  2. Uberpete

    Uberpete

    Joined:
    Jan 16, 2014
    Posts:
    78
    Try using scale instead:

    Code (CSharp):
    1.         Vector3 FlipScale = transform.localScale;
    2.         FlipScale.x *= -1;
    3.         transform.localScale = FlipScale;