- Home /
How to detect if target is inside an "arc" area?
I'm trying to implement an "Arc" attack in an isometric game (Inspired in part by Hades). After looking through several resources, I ended up getting stuck after reading this answer (And this).
It almost works, but surely the method is flawed? Using the following drawing, I will explain my issue. (Red targets are removed in each step.)
A: First I make a simple OverlapSphere check to exclude colliders completely outside the range.
List<Collider> collidersInMaxRange = Physics.OverlapSphere(position, MaxRange).ToList();
B: Then I check if any targets are within the minimum range, without touching the area.
private bool InsideMinRange(Vector3 position, float minRange, Collider target)
{
var colliderCenter = target.transform.position;
Vector3 positionToCollider = colliderCenter - position;
Vector3 otherSide = colliderCenter + positionToCollider;
Vector3 farthestPoint = target.ClosestPoint(otherSide);
return Vector3.Distance(position, farthestPoint) < minRange;
}
C: Here's where I'm stuck. Using the following method -
private bool OutsideAngle(Vector3 position, Vector3 forwardVector, float angle, Collider target)
{
Vector3 directionToTarget = (position - target.transform.position).normalized;
return Vector3.Dot(directionToTarget, forwardVector) > angle / 180;
}
target 1 and 2 are excluded because there centers are outside the arc, even though a part of them is inside. How can I change my code to include target 1 and 2?
arc-attack.png
(31.2 kB)
Comment