From 09d54136f6425228db4921ac57900fa18f1c2db4 Mon Sep 17 00:00:00 2001 From: Ny Bruker <robinhs@stud.ntnu.no> Date: Tue, 27 Sep 2022 12:48:14 +0200 Subject: [PATCH] Fixing knockback & movement. - Adjusting the knockback to be reasonable level. - Rewrite movement code to use acceleration. --- MrBigsock/Assets/Code/PlayerController.cs | 13 ++++++++++++- MrBigsock/Assets/Code/attack/AttackMovement.cs | 4 ++-- MrBigsock/Assets/Code/orc/EnemyController.cs | 10 +++++++++- MrBigsock/Assets/Prefabs/BigSock.prefab | 7 ++++--- MrBigsock/Assets/Prefabs/Enemy_Slime.prefab | 2 +- MrBigsock/Assets/Prefabs/attack.prefab | 1 + MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab | 10 +++++----- 7 files changed, 34 insertions(+), 13 deletions(-) diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index f8fad127..ded60e8f 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -104,7 +104,17 @@ namespace BigSock { } } + private bool TryMove(Vector2 direction) { + if(direction != Vector2.zero) { + rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse); + return true; + } + return false; + } + + + private bool TryMove_OLD(Vector2 direction) { if(direction != Vector2.zero) { // Check for potential collisions int count = rb.Cast( @@ -123,7 +133,8 @@ namespace BigSock { // Can't move if there's no direction to move in return false; } - + + // } void OnMove(InputValue movementValue) { diff --git a/MrBigsock/Assets/Code/attack/AttackMovement.cs b/MrBigsock/Assets/Code/attack/AttackMovement.cs index f8cc663f..4768aed3 100644 --- a/MrBigsock/Assets/Code/attack/AttackMovement.cs +++ b/MrBigsock/Assets/Code/attack/AttackMovement.cs @@ -19,7 +19,7 @@ namespace BigSock { public float baseDamage = 1; public float KnockbackForce => knockbackForce; - public float knockbackForce = 50; + public float knockbackForce = 1; // Start is called before the first frame update @@ -50,7 +50,7 @@ namespace BigSock { void OnCollisionEnter2D(Collision2D collision) { print($"[AttackMovement.OnCollisionEnter2D()] {collision.transform.position}"); - var target = collision.gameObject.GetComponent<EnemyController>(); + var target = collision.gameObject.GetComponent<Character>(); if(target != null) { diff --git a/MrBigsock/Assets/Code/orc/EnemyController.cs b/MrBigsock/Assets/Code/orc/EnemyController.cs index ed68aac6..02dbc762 100644 --- a/MrBigsock/Assets/Code/orc/EnemyController.cs +++ b/MrBigsock/Assets/Code/orc/EnemyController.cs @@ -38,7 +38,7 @@ namespace BigSock { followCollider.OnColliderStay2D_Action += Move_OnColliderStay2D; followCollider.OnColliderExit2D_Action += Move_OnColliderExit2D; - attackCollider = transform.Find("AttackCollider").GetComponent<EmptyCollider>(); + attackCollider = transform.Find("MeleeCollider").GetComponent<EmptyCollider>(); attackCollider.OnColliderEnter2D_Action += Attack_OnColliderEnter2D; attackCollider.OnColliderStay2D_Action += Attack_OnColliderStay2D; attackCollider.OnColliderExit2D_Action += Attack_OnColliderExit2D; @@ -79,6 +79,14 @@ namespace BigSock { } private bool TryMove(Vector2 direction) { + if(direction != Vector2.zero) { + rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse); + return true; + } + return false; + } + + private bool TryMove_OLD(Vector2 direction) { if(direction != Vector2.zero) { diff --git a/MrBigsock/Assets/Prefabs/BigSock.prefab b/MrBigsock/Assets/Prefabs/BigSock.prefab index 43774917..b1a26ff4 100644 --- a/MrBigsock/Assets/Prefabs/BigSock.prefab +++ b/MrBigsock/Assets/Prefabs/BigSock.prefab @@ -132,11 +132,12 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: baseAttackSpeed: 4 - baseMovementSpeed: 3 + baseMovementSpeed: 10 baseDamage: 1 - KnockbackForce: 150 + knockbackForce: 150 baseHP: 10 baseMaxHP: 10 + hpBar: {fileID: 0} collisionOffset: 0.05 movementFilter: useTriggers: 0 @@ -166,7 +167,7 @@ Rigidbody2D: m_UseFullKinematicContacts: 0 m_UseAutoMass: 0 m_Mass: 1 - m_LinearDrag: 1 + m_LinearDrag: 2 m_AngularDrag: 0.05 m_GravityScale: 0 m_Material: {fileID: 0} diff --git a/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab b/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab index 55991571..04d11513 100644 --- a/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab +++ b/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab @@ -103,7 +103,7 @@ Rigidbody2D: m_UseFullKinematicContacts: 1 m_UseAutoMass: 1 m_Mass: 0.6243647 - m_LinearDrag: 2.5 + m_LinearDrag: 2 m_AngularDrag: 0 m_GravityScale: 0 m_Material: {fileID: 0} diff --git a/MrBigsock/Assets/Prefabs/attack.prefab b/MrBigsock/Assets/Prefabs/attack.prefab index 22ddb361..7e3c9698 100644 --- a/MrBigsock/Assets/Prefabs/attack.prefab +++ b/MrBigsock/Assets/Prefabs/attack.prefab @@ -161,3 +161,4 @@ MonoBehaviour: m_EditorClassIdentifier: speed: 10 baseDamage: 1 + knockbackForce: 1 diff --git a/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab b/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab index 9df14e8d..d4d25a7d 100644 --- a/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab +++ b/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab @@ -103,7 +103,7 @@ Rigidbody2D: m_UseFullKinematicContacts: 1 m_UseAutoMass: 1 m_Mass: 0.6243647 - m_LinearDrag: 2.5 + m_LinearDrag: 2 m_AngularDrag: 0 m_GravityScale: 0 m_Material: {fileID: 0} @@ -144,9 +144,9 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: baseAttackSpeed: 1 - baseMovementSpeed: 2 + baseMovementSpeed: 4 baseDamage: 1 - KnockbackForce: 150 + knockbackForce: 3 baseHP: 10 baseMaxHP: 10 collisionOffset: 0.05 @@ -248,7 +248,7 @@ MonoBehaviour: m_GameObject: {fileID: 7539630614846898202} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b1aeda8fe8f5c1f4fa7a8f47e2864211, type: 3} + m_Script: {fileID: 11500000, guid: 02e1a714e20472c46a1f156e232741cd, type: 3} m_Name: m_EditorClassIdentifier: --- !u!1 &8620845285361089561 @@ -309,6 +309,6 @@ MonoBehaviour: m_GameObject: {fileID: 8620845285361089561} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b1aeda8fe8f5c1f4fa7a8f47e2864211, type: 3} + m_Script: {fileID: 11500000, guid: 02e1a714e20472c46a1f156e232741cd, type: 3} m_Name: m_EditorClassIdentifier: -- GitLab