Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Sprite reversing not working

Discussion in 'Scripting' started by Kinkku2, Aug 18, 2015.

  1. Kinkku2

    Kinkku2

    Joined:
    Sep 29, 2014
    Posts:
    106
    Hey! I have a script that flips the player around to face the correct direction, but it's not quite working. When I touch a movable and start pushing, the player turns around for a blink and then flips back to the wrong direction. The problem is that when the player hits the movable's collider the collider enters it twice and exits it once. Why does the collider enter twice? Here's the script I have:

    Code (CSharp):
    1. void OnCollisionEnter2D(Collision2D collision) {
    2.  
    3.         canJump = true;
    4.  
    5.         if(collision.collider.tag == "Movable") {
    6.             pushing = true;
    7.             TurnPlayerAround();
    8.         }
    9.     }
    10.  
    11.     void OnCollisionExit2D(Collision2D collision) {
    12.  
    13.         if(collision.collider.tag == "Ground") {
    14.             canJump = false;
    15.         }
    16.  
    17.         if(collision.collider.tag == "Movable") {
    18.             Debug.Log("WentToExit");
    19.             pushing = false;
    20.             canJump = true;
    21.         }
    22.     }
    23.  
    24.     void TurnPlayerAround () {
    25.         scale.x *= -1;
    26.         transform.localScale = scale;
    27.   }
    28.        
     
    Last edited: Aug 18, 2015
unityunity