Fire_Wizard

PASTE

Jun 30th, 2021 (edited)
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1.  private void FixedUpdate()
  2.     {
  3.         if(currentState != States.Attacking && currentState != States.InKnockback)
  4.         {
  5.             velocity = Vector2.Lerp(velocity, inputVector * myMobInfo.MovementSpeed, myMobInfo.MovementLerpWeight);
  6.             myRigidbody.velocity = velocity;
  7.         }
  8.         else if(currentState != States.InKnockback)
  9.         {
  10.             velocity = Vector2.zero;
  11.             myRigidbody.velocity = velocity;
  12.  
  13.         }
  14.         if (Mathf.Abs(myRigidbody.velocity.x) < 0.1f && Mathf.Abs(myRigidbody.velocity.y) < 0.1f) myRigidbody.velocity = Vector2.zero;
  15.     }
  16.  
  17.    private States GetNewState()
  18.     {
  19.         switch (currentState)
  20.         {
  21.             // Other states are removed for shorter length
  22.             case States.InKnockback:
  23.                 if(myRigidbody.velocity == Vector2.zero)
  24.                 {
  25.                     if (isAttacking > 0) return States.Attacking;
  26.                     knockbackEndpoint = Vector2.zero;
  27.                     return States.Idle;
  28.                 }
  29.                 return States.InKnockback;
  30.         }
  31.     }
  32.    
  33.     public void GetKnockback(Vector2 knockbackEndpoint)
  34.     {
  35.         currentState = States.InKnockback;
  36.         var dir = (knockbackEndpoint - (Vector2)transform.position);
  37.         myRigidbody.AddForce(dir.normalized * 10, ForceMode2D.Impulse);
  38.  
  39.     }
  40.  
  41.  
Add Comment
Please, Sign In to add comment