From 3c07d91ec84d73b0010d34d59d15672ff2ee9955 Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Fri, 25 Oct 2024 14:02:48 -0700 Subject: [PATCH 1/7] Swing in correct direction --- Assets/C# Scripts/Teo.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Assets/C# Scripts/Teo.cs b/Assets/C# Scripts/Teo.cs index 2abcc9c..c8194a2 100644 --- a/Assets/C# Scripts/Teo.cs +++ b/Assets/C# Scripts/Teo.cs @@ -58,11 +58,11 @@ public class Teo : MonoBehaviour // If ratbot exists and is within swing range, damage it. // Calculate absolute difference between angles of ratbot and cursor if (ratbot == null || Mathf.Abs(Mathf.Atan2( - ratbot.transform.position.y - transform.position.y, - ratbot.transform.position.x - transform.position.x + hit.transform.position.y - transform.position.y, + hit.transform.position.x - transform.position.x ) - Mathf.Atan2( - Screen.height/2 - Input.mousePosition.y, - Screen.width/2 - Input.mousePosition.x + Input.mousePosition.y - Screen.height/2, + Input.mousePosition.x - Screen.width/2 )) > swingRangeDeg * Mathf.Deg2Rad ) continue; ratbot.Damage(damageStrength); From f21ed7fc1932d1a02b4fdba5084c0daf2bdead28 Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Fri, 25 Oct 2024 14:21:06 -0700 Subject: [PATCH 2/7] Pretty sure swinging works as intended now --- Assets/Enemy/Ratbot.prefab | 2 +- Assets/Player/DistanceIndicator.prefab | 2 +- Assets/Scenes/SampleScene.unity | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/Enemy/Ratbot.prefab b/Assets/Enemy/Ratbot.prefab index f61fb03..9182b9f 100644 --- a/Assets/Enemy/Ratbot.prefab +++ b/Assets/Enemy/Ratbot.prefab @@ -29,7 +29,7 @@ Transform: m_GameObject: {fileID: 398740452138961375} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -11.37, y: -2.4779136, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.45, y: 0.45, z: 0.45} m_ConstrainProportionsScale: 1 m_Children: [] diff --git a/Assets/Player/DistanceIndicator.prefab b/Assets/Player/DistanceIndicator.prefab index bcc1ea0..ca45d53 100644 --- a/Assets/Player/DistanceIndicator.prefab +++ b/Assets/Player/DistanceIndicator.prefab @@ -100,4 +100,4 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 23dc3f32eba4c9e5aad24589fdbfa30c, type: 3} m_Name: m_EditorClassIdentifier: - multiplier: 2.8 + multiplier: 1 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index fe487b7..59c0db0 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -325,7 +325,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3} propertyPath: swingDistance - value: 1 + value: 3 objectReference: {fileID: 0} - target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3} propertyPath: distanceIndicator From ca280d700e964658d710327c77c052dd4cdc05b9 Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sat, 26 Oct 2024 21:25:03 -0700 Subject: [PATCH 3/7] Resolve merge conflicts from main menu --- Assets/Scenes/SampleScene.unity | 8 ++++---- Assets/Scripts C#/Teo.cs | 12 +----------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 4fe4b7a..7f0dbe7 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -325,11 +325,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3} propertyPath: swingDistance -<<<<<<< HEAD value: 3 -======= - value: 2 ->>>>>>> main + objectReference: {fileID: 0} + - target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3} + propertyPath: swingRangeDeg + value: 21.98 objectReference: {fileID: 0} - target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3} propertyPath: distanceIndicator diff --git a/Assets/Scripts C#/Teo.cs b/Assets/Scripts C#/Teo.cs index 7476678..c8194a2 100644 --- a/Assets/Scripts C#/Teo.cs +++ b/Assets/Scripts C#/Teo.cs @@ -57,24 +57,14 @@ public class Teo : MonoBehaviour Ratbot ratbot = hit.GetComponent(); // If ratbot exists and is within swing range, damage it. // Calculate absolute difference between angles of ratbot and cursor -<<<<<<< HEAD:Assets/C# Scripts/Teo.cs if (ratbot == null || Mathf.Abs(Mathf.Atan2( hit.transform.position.y - transform.position.y, hit.transform.position.x - transform.position.x -======= - /* if (ratbot == null || Mathf.Abs(Mathf.Atan2( - ratbot.transform.position.y - transform.position.y, - ratbot.transform.position.x - transform.position.x ->>>>>>> main:Assets/Scripts C#/Teo.cs ) - Mathf.Atan2( Input.mousePosition.y - Screen.height/2, Input.mousePosition.x - Screen.width/2 )) > swingRangeDeg * Mathf.Deg2Rad - ) */ - if (ratbot == null) { - continue; - } - + ) continue; ratbot.Damage(damageStrength); } } From e3c8dfcfa7c8b1e818e85729f662cabf5f83a794 Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sat, 26 Oct 2024 22:46:03 -0700 Subject: [PATCH 4/7] Use closest point instead of center Check if the closest point of an enemy is in range instead of checking the center --- Assets/Scripts C#/Teo.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts C#/Teo.cs b/Assets/Scripts C#/Teo.cs index c8194a2..d99982e 100644 --- a/Assets/Scripts C#/Teo.cs +++ b/Assets/Scripts C#/Teo.cs @@ -57,9 +57,14 @@ public class Teo : MonoBehaviour Ratbot ratbot = hit.GetComponent(); // If ratbot exists and is within swing range, damage it. // Calculate absolute difference between angles of ratbot and cursor - if (ratbot == null || Mathf.Abs(Mathf.Atan2( - hit.transform.position.y - transform.position.y, - hit.transform.position.x - transform.position.x + if (ratbot == null) continue; + Vector2 hitClosest = Physics2D.ClosestPoint( + transform.position, + hit + ); + if (Mathf.Abs(Mathf.Atan2( + hitClosest.y - transform.position.y, + hitClosest.x - transform.position.x ) - Mathf.Atan2( Input.mousePosition.y - Screen.height/2, Input.mousePosition.x - Screen.width/2 From de3873f5903986565ae0243c7b8d74ca21f86c0c Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sat, 26 Oct 2024 23:32:16 -0700 Subject: [PATCH 5/7] Apply multiplier to damage strength based on attack cooldown --- Assets/Player/Player.prefab | 4 ++-- Assets/Scenes/SampleScene.unity | 2 +- Assets/Scripts C#/Teo.cs | 20 ++++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Assets/Player/Player.prefab b/Assets/Player/Player.prefab index dc7e746..800706d 100644 --- a/Assets/Player/Player.prefab +++ b/Assets/Player/Player.prefab @@ -106,8 +106,8 @@ MonoBehaviour: health: 100 maxHealth: 100 moveSpeed: 15 - swingRange: 2 - swingDistance: 10 + swingRangeDeg: 3 + swingDistance: 2 damageStrength: 10 attackCooldownSeconds: 2 dashDistance: 20 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 7f0dbe7..0682f9b 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -329,7 +329,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3} propertyPath: swingRangeDeg - value: 21.98 + value: 10 objectReference: {fileID: 0} - target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3} propertyPath: distanceIndicator diff --git a/Assets/Scripts C#/Teo.cs b/Assets/Scripts C#/Teo.cs index d99982e..a02fcda 100644 --- a/Assets/Scripts C#/Teo.cs +++ b/Assets/Scripts C#/Teo.cs @@ -43,9 +43,6 @@ public class Teo : MonoBehaviour } } void Attack() { - if (Time.fixedTime-lastAttackTime < attackCooldownSeconds) { - return; - } Instantiate(distanceIndicator, transform); // Get all objects within swingDistance of player Collider2D[] hits = Physics2D.OverlapCircleAll( @@ -55,13 +52,13 @@ public class Teo : MonoBehaviour // Damage all ratbots in scanned area foreach (Collider2D hit in hits) { Ratbot ratbot = hit.GetComponent(); - // If ratbot exists and is within swing range, damage it. - // Calculate absolute difference between angles of ratbot and cursor if (ratbot == null) continue; + // Find the closest point on the ratbot Vector2 hitClosest = Physics2D.ClosestPoint( - transform.position, - hit + transform.position, hit ); + // If ratbot's closest point within swing range, damage it. + // Calculate absolute difference between angles of ratbot and cursor if (Mathf.Abs(Mathf.Atan2( hitClosest.y - transform.position.y, hitClosest.x - transform.position.x @@ -70,22 +67,29 @@ public class Teo : MonoBehaviour Input.mousePosition.x - Screen.width/2 )) > swingRangeDeg * Mathf.Deg2Rad ) continue; - ratbot.Damage(damageStrength); + // Apply a multiplier to damageStrength based on attack cooldown. + // If multiplier > 1, just do damageStrength + // Fuck readability, it's a one liner now + Debug.Log(Mathf.Min(damageStrength * (Time.fixedTime - lastAttackTime)/attackCooldownSeconds, damageStrength)); + ratbot.Damage(Mathf.Min(damageStrength * (Time.fixedTime - lastAttackTime)/attackCooldownSeconds, damageStrength)); } } IEnumerator Dash() { BoxCollider2D collider = GetComponent(); + // Disable collision and linearDamping while dashing lastDashTime = Time.fixedTime; dashing = true; collider.enabled = false; controller.linearDamping = 0; controller.linearVelocity = Vector2.zero; + // Apply a force to player towards mouse cursor controller.AddRelativeForce (new Vector2( Input.mousePosition.x - Screen.width/2, Input.mousePosition.y - Screen.height/2 ).normalized * dashDistance); // Wait 0.2 seconds before ending the dash yield return new WaitForSeconds(0.2F); + // Re enable collision and linearDamping after dash complete dashing = false; collider.enabled = true; controller.linearDamping = 15; From 3dd0e0f4397ef96137648e4cecc4c225be3389c5 Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sat, 26 Oct 2024 23:51:17 -0700 Subject: [PATCH 6/7] Spam punish multiplier --- Assets/Scripts C#/Teo.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts C#/Teo.cs b/Assets/Scripts C#/Teo.cs index a02fcda..af79b9e 100644 --- a/Assets/Scripts C#/Teo.cs +++ b/Assets/Scripts C#/Teo.cs @@ -10,6 +10,7 @@ public class Teo : MonoBehaviour public float swingDistance = 10; public float damageStrength = 10; public float attackCooldownSeconds = 10; + public float spamPunishMultiplier = 0.5F; public float dashDistance = 5F; public float dashCooldownSeconds = 5; public float lastAttackTime = 0; @@ -69,9 +70,12 @@ public class Teo : MonoBehaviour ) continue; // Apply a multiplier to damageStrength based on attack cooldown. // If multiplier > 1, just do damageStrength - // Fuck readability, it's a one liner now - Debug.Log(Mathf.Min(damageStrength * (Time.fixedTime - lastAttackTime)/attackCooldownSeconds, damageStrength)); - ratbot.Damage(Mathf.Min(damageStrength * (Time.fixedTime - lastAttackTime)/attackCooldownSeconds, damageStrength)); + float damageAmount = damageStrength * (Time.fixedTime - lastAttackTime)/attackCooldownSeconds; + ratbot.Damage( + (damageAmount > damageStrength) + ? damageStrength + : damageAmount * spamPunishMultiplier + ); } } IEnumerator Dash() { From 6f5114b495bc1e0ffd5929113d893afe7740c629 Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sun, 27 Oct 2024 00:18:18 -0700 Subject: [PATCH 7/7] Attack damage scales quadratic with time until at damageStrength --- Assets/Scripts C#/Ratbot.cs | 1 + Assets/Scripts C#/Teo.cs | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts C#/Ratbot.cs b/Assets/Scripts C#/Ratbot.cs index 692ccc1..94a3eba 100644 --- a/Assets/Scripts C#/Ratbot.cs +++ b/Assets/Scripts C#/Ratbot.cs @@ -33,6 +33,7 @@ public class Ratbot : MonoBehaviour // Die if health below zero public void Damage(float hurtyAmount) { + Debug.Log(hurtyAmount); health -= hurtyAmount; if (health <= 0) { Destroy(gameObject); diff --git a/Assets/Scripts C#/Teo.cs b/Assets/Scripts C#/Teo.cs index af79b9e..32d3042 100644 --- a/Assets/Scripts C#/Teo.cs +++ b/Assets/Scripts C#/Teo.cs @@ -10,7 +10,6 @@ public class Teo : MonoBehaviour public float swingDistance = 10; public float damageStrength = 10; public float attackCooldownSeconds = 10; - public float spamPunishMultiplier = 0.5F; public float dashDistance = 5F; public float dashCooldownSeconds = 5; public float lastAttackTime = 0; @@ -68,13 +67,15 @@ public class Teo : MonoBehaviour Input.mousePosition.x - Screen.width/2 )) > swingRangeDeg * Mathf.Deg2Rad ) continue; - // Apply a multiplier to damageStrength based on attack cooldown. - // If multiplier > 1, just do damageStrength - float damageAmount = damageStrength * (Time.fixedTime - lastAttackTime)/attackCooldownSeconds; + // Apply x^2 multiplier to damage if not fully charged + // Just use damageStrength if fully charged + float timeWaited = Time.fixedTime - lastAttackTime; ratbot.Damage( - (damageAmount > damageStrength) - ? damageStrength - : damageAmount * spamPunishMultiplier + (timeWaited < attackCooldownSeconds) + ? Mathf.Pow(timeWaited, 2) * + damageStrength / + Mathf.Pow(attackCooldownSeconds, 2) + : damageStrength ); } }