From e3c8dfcfa7c8b1e818e85729f662cabf5f83a794 Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sat, 26 Oct 2024 22:46:03 -0700 Subject: [PATCH] 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