Answers for "unity 2d flip"

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
-2

unity c# flip sprite

public Camera cam;
   public Transform aimTransform;



Vector3 mousePosition = cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y));
        Vector3 aimDirection = (mousePosition - transform.position).normalized;
        float angle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg;
        aimTransform.eulerAngles = new Vector3(0, 0, angle);
Posted by: Guest on October-14-2020

Browse Popular Code Answers by Language