diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index 9cfe71a8cc53a219aa5dc230a91f00a9428a0ddc..778cc2bdf1736cd19083766ea5c5861777f2f0cc 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -27,6 +27,11 @@ namespace BigSock { public double Damage => baseDamage; public double baseDamage = 1; + /* + Knockback force + */ + public float KnockbackForce = 150; + /* Hit points of the character. diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index 11b0f6cd4c1db95979403211984310ac14fe7904..14ad33e4619c7630c5d6a7b297647ed90d7a62d2 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -52,12 +52,22 @@ namespace BigSock { // Add damage HP -= amount; + // Knockback + TryKill(); return true; } + /* + Add Kcockback. + */ + public void KnockBack(float force, Vector2 difference){ + rb.AddForce(difference * force); + + } + /* Try to kill the player. */ diff --git a/MrBigsock/Assets/Code/orc/EnemyController.cs b/MrBigsock/Assets/Code/orc/EnemyController.cs index 375479393dfb552fbf14a9933898b9c7686eec4e..b3dd0dc17f8f54c2e2185cde1e2e0bc1d2da761e 100644 --- a/MrBigsock/Assets/Code/orc/EnemyController.cs +++ b/MrBigsock/Assets/Code/orc/EnemyController.cs @@ -37,7 +37,7 @@ namespace BigSock { followCollider.OnColliderStay2D_Action += Move_OnColliderStay2D; followCollider.OnColliderExit2D_Action += Move_OnColliderExit2D; - attackCollider = transform.Find("MeleeCollider").GetComponent<EmptyCollider>(); + attackCollider = transform.Find("AttackCollider").GetComponent<EmptyCollider>(); attackCollider.OnColliderEnter2D_Action += Attack_OnColliderEnter2D; attackCollider.OnColliderStay2D_Action += Attack_OnColliderStay2D; attackCollider.OnColliderExit2D_Action += Attack_OnColliderExit2D; @@ -119,7 +119,9 @@ namespace BigSock { if (other.gameObject.tag == "Player"){ var player = other.gameObject.GetComponent<PlayerController>(); if(player.TakeDamage(Damage)){ - //knockback ? + //rb position - player position + Vector2 difference = (other.transform.position - transform.position).normalized; + player.KnockBack(KnockbackForce, difference); //animer nå ? } diff --git a/MrBigsock/ProjectSettings/TagManager.asset b/MrBigsock/ProjectSettings/TagManager.asset index 1c92a7840ec11895c76785f65d949a3d20d53355..46714474db620d273834fdca4b508690b5aa8890 100644 --- a/MrBigsock/ProjectSettings/TagManager.asset +++ b/MrBigsock/ProjectSettings/TagManager.asset @@ -8,12 +8,12 @@ TagManager: - Default - TransparentFX - Ignore Raycast - - + - collider - Water - UI - - - - - - + - enemy + - wall + - player - - -