From ff2699ba9575eb04abe42623fedf1c002c0b4c9e Mon Sep 17 00:00:00 2001
From: Gard <gardaf@stud.ntnu.no>
Date: Sat, 10 Dec 2022 03:45:52 +0100
Subject: [PATCH] made movement use moveposition and added a timer for
 knockback to remove speed

---
 MrBigsock/Assets/Code/Character.cs            | 30 ++++++++++++++-----
 .../Code/Core/Abilities/AbilityDodge.cs       |  2 +-
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs
index 75120bfb..2dfb4461 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 ff78922d..8b5f40ef 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;
-- 
GitLab