Advertisement
LeeMace

Flip Player when change direction

Mar 9th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | Gaming | 0 0
  1.  void Update()
  2.     {
  3.         targetVelocity = new Vector2(Input.GetAxis("Horizontal") * maxSpeed, 0);
  4.  
  5.         if (Input.GetButtonDown("Jump") && grounded)
  6.         {
  7.             velocity.y = jumpPower;
  8.         }
  9.  
  10.         //flip the player if moving left or right
  11.         if(targetVelocity.x < -.01)
  12.         {
  13.             transform.localScale = new Vector2(-1, 1);
  14.         }
  15.         else if(targetVelocity.x > .01)
  16.         {
  17.             transform.localScale = new Vector2(1, 1);
  18.         }
  19.     }
Tags: flip player
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement