Use closest point instead of center
Check if the closest point of an enemy is in range instead of checking the center
This commit is contained in:
@@ -57,9 +57,14 @@ public class Teo : MonoBehaviour
|
|||||||
Ratbot ratbot = hit.GetComponent<Ratbot>();
|
Ratbot ratbot = hit.GetComponent<Ratbot>();
|
||||||
// If ratbot exists and is within swing range, damage it.
|
// If ratbot exists and is within swing range, damage it.
|
||||||
// Calculate absolute difference between angles of ratbot and cursor
|
// Calculate absolute difference between angles of ratbot and cursor
|
||||||
if (ratbot == null || Mathf.Abs(Mathf.Atan2(
|
if (ratbot == null) continue;
|
||||||
hit.transform.position.y - transform.position.y,
|
Vector2 hitClosest = Physics2D.ClosestPoint(
|
||||||
hit.transform.position.x - transform.position.x
|
transform.position,
|
||||||
|
hit
|
||||||
|
);
|
||||||
|
if (Mathf.Abs(Mathf.Atan2(
|
||||||
|
hitClosest.y - transform.position.y,
|
||||||
|
hitClosest.x - transform.position.x
|
||||||
) - Mathf.Atan2(
|
) - Mathf.Atan2(
|
||||||
Input.mousePosition.y - Screen.height/2,
|
Input.mousePosition.y - Screen.height/2,
|
||||||
Input.mousePosition.x - Screen.width/2
|
Input.mousePosition.x - Screen.width/2
|
||||||
|
|||||||
Reference in New Issue
Block a user