diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index 75120bfb210fa3f8f124b0e374222f6ceb2059e4..2dfb4461e03037b899e2ddab7b121137014ae4a5 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -88,6 +88,9 @@ namespace BigSock { // The direction the character last moved. protected Vector2 moveDir; + // trigger for in knockback. + protected bool inKnockBack = false; + /* The inventory of the character. @@ -178,20 +181,30 @@ namespace BigSock { MovementDir = moveDir, }; } - - + /* + Using a courutine to set trigger in knockback. + */ + IEnumerator knockBackTimer() + { + inKnockBack = true; + yield return new WaitForSeconds(0.15F); + rb.velocity = Vector2.zero; + inKnockBack = false; + } /* - Add Knockback. + Add Knockback. (used only for dash ?) */ public void KnockBack(float force, Vector2 difference) { rb.AddForce(difference * force, ForceMode2D.Impulse); + StartCoroutine(knockBackTimer()); + + //rb.MovePosition((Vector2)transform.position + (difference * force * Time.fixedDeltaTime)); } public void KnockBack(IAttackStats attack) { Vector2 difference = ((Vector2) transform.position - attack.Source).normalized; - //KnockBack(attack.Knockback, difference); rb.AddForce(difference * attack.Knockback, ForceMode2D.Impulse); - + StartCoroutine(knockBackTimer()); } /* @@ -199,8 +212,11 @@ namespace BigSock { */ protected virtual bool TryMove(Vector2 direction) { moveDir = direction; - if(direction != Vector2.zero) { - rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse); + if(direction != Vector2.zero && !inKnockBack) { + //Using movePosition to get a "snappy" movement. + //rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse); + rb.MovePosition((Vector2)transform.position + (direction * (float) MovementSpeed * Time.fixedDeltaTime)); + //rb.velocity = (direction * (float) MovementSpeed); return true; } return false; diff --git a/MrBigsock/Assets/Code/Core/Abilities/AbilityDodge.cs b/MrBigsock/Assets/Code/Core/Abilities/AbilityDodge.cs index ff78922d6c34590ab574eaedb5b229a9e5b60f27..8b5f40eff90d722cd209ed1285e4a07b70a5f2df 100644 --- a/MrBigsock/Assets/Code/Core/Abilities/AbilityDodge.cs +++ b/MrBigsock/Assets/Code/Core/Abilities/AbilityDodge.cs @@ -13,7 +13,7 @@ namespace BigSock { A basic dodge move that gives a push and a short invincibility. */ public class AbilityDodge : BaseAbility { - public static readonly float BASE_FORCE = 0.5f; + public static readonly float BASE_FORCE = 1f; public static readonly TimeSpan IFRAME_DURATION = new TimeSpan(0, 0, 0, 0, 500); public override ulong Id => 201;