Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void FixedUpdate()
- {
- if(currentState != States.Attacking && currentState != States.InKnockback)
- {
- velocity = Vector2.Lerp(velocity, inputVector * myMobInfo.MovementSpeed, myMobInfo.MovementLerpWeight);
- myRigidbody.velocity = velocity;
- }
- else if(currentState != States.InKnockback)
- {
- velocity = Vector2.zero;
- myRigidbody.velocity = velocity;
- }
- if (Mathf.Abs(myRigidbody.velocity.x) < 0.1f && Mathf.Abs(myRigidbody.velocity.y) < 0.1f) myRigidbody.velocity = Vector2.zero;
- }
- private States GetNewState()
- {
- switch (currentState)
- {
- // Other states are removed for shorter length
- case States.InKnockback:
- if(myRigidbody.velocity == Vector2.zero)
- {
- if (isAttacking > 0) return States.Attacking;
- knockbackEndpoint = Vector2.zero;
- return States.Idle;
- }
- return States.InKnockback;
- }
- }
- public void GetKnockback(Vector2 knockbackEndpoint)
- {
- currentState = States.InKnockback;
- var dir = (knockbackEndpoint - (Vector2)transform.position);
- myRigidbody.AddForce(dir.normalized * 10, ForceMode2D.Impulse);
- }
Add Comment
Please, Sign In to add comment