Answers for "how to flip the player unity 2d"

3

how to make player flip when pressing a d unity 2d

void  Update ()
    {  //This short code makes player flip when the A and D or arrow keys are pressed.

        Vector3 charecterScale = transform.localScale;
        if (Input.GetAxis("Horizontal") < 0)
        {
            charecterScale.x = -10;
        } 
        if (Input.GetAxis("Horizontal") > 0)
        {
            charecterScale.x = 10;
        }
        transform.localScale = charecterScale;
    }
Posted by: Guest on October-03-2020
2

how to flip character in unity 2d

Put this in Update() = 

    //Flip the player's localScale.x 
    if the move speed is greater than .01 or less than -.01

        if (targetVelocity.x < -.01)
        {
            transform.eulerAngles = new Vector3(0, 180, 0); // Flipped
        }
        else if (targetVelocity.x > .01)
        {
            transform.eulerAngles = new Vector3(0, 0, 0); // Normal
        }
Posted by: Guest on July-16-2021

Code answers related to "how to flip the player unity 2d"

Browse Popular Code Answers by Language