diff --git a/Assets/C# Scripts/ShopButton.cs b/Assets/C# Scripts/ShopButton.cs index f68605d..c9c0975 100644 --- a/Assets/C# Scripts/ShopButton.cs +++ b/Assets/C# Scripts/ShopButton.cs @@ -21,7 +21,7 @@ public class ShopButton : MonoBehaviour Teo player = GameObject.FindGameObjectWithTag("Player").GetComponent(); switch (upgrade) { case UpgradeOption.AttackRange: - player.swingRange += amount; + player.swingRangeDeg += amount; break; case UpgradeOption.AttackDistance: player.swingDistance += amount; diff --git a/Assets/C# Scripts/Teo.cs b/Assets/C# Scripts/Teo.cs index f7c07be..2abcc9c 100644 --- a/Assets/C# Scripts/Teo.cs +++ b/Assets/C# Scripts/Teo.cs @@ -6,7 +6,7 @@ public class Teo : MonoBehaviour public float health = 100; public float maxHealth = 100; public float moveSpeed = 10; - public float swingRange = 3; + public float swingRangeDeg = 3; public float swingDistance = 10; public float damageStrength = 10; public float attackCooldownSeconds = 10; @@ -47,20 +47,24 @@ public class Teo : MonoBehaviour return; } Instantiate(distanceIndicator, transform); - // Get all objects in range in the direction of cursor - RaycastHit2D[] hits = Physics2D.CircleCastAll( + // Get all objects within swingDistance of player + Collider2D[] hits = Physics2D.OverlapCircleAll( transform.position, - swingRange, - new Vector2( - Input.mousePosition.x - Screen.width/2, - Input.mousePosition.y - Screen.height/2 - ).normalized, swingDistance ); // Damage all ratbots in scanned area - foreach (RaycastHit2D hit in hits) { - Ratbot ratbot = hit.collider.GetComponent(); - if (ratbot == null) continue; + 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 || Mathf.Abs(Mathf.Atan2( + ratbot.transform.position.y - transform.position.y, + ratbot.transform.position.x - transform.position.x + ) - Mathf.Atan2( + Screen.height/2 - Input.mousePosition.y, + Screen.width/2 - Input.mousePosition.x + )) > swingRangeDeg * Mathf.Deg2Rad + ) continue; ratbot.Damage(damageStrength); } } @@ -75,6 +79,7 @@ public class Teo : MonoBehaviour 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); dashing = false; collider.enabled = true; diff --git a/Assets/Shop/Shop.prefab b/Assets/Shop/Shop.prefab index 5997da7..730a2ac 100644 --- a/Assets/Shop/Shop.prefab +++ b/Assets/Shop/Shop.prefab @@ -1046,7 +1046,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: upgrade: 0 - amount: 1 + amount: 1.5 --- !u!1 &3627401992951871319 GameObject: m_ObjectHideFlags: 0