I’m trying make a cleave style melee attack where the character swings and hits all targets in an arc front of her. The range of her attack and arc of the swing are variable.
I’m trying to do this by detecting all hittable objects in a sphere around the character, then comparing the direction she’s facing to the location of the target. Vector3.Angle feels like it’s close to the answer, but it gives the angle from the origin and I want the angle from the character. I don’t understand the underlying math, but I anticipate there is a high level function that can find this angle.
`
public void AttackHitFrame()
{
var coneAngle = 45.0f;
var attackRadius = 5;
var hit = Physics.OverlapSphere(transform.position, attackRadius);
foreach (var hitObject in hit)
{
//Hittable entity is a hittable mono behavior
var hittable = hitObject.GetComponent<IHittable>() as HittableEntity;
if (hittable != null)
{
var angleToTarget = Vector3.Angle(transform.forward, hittable.transform.forward);
Debug.Log(angleToTarget);
if (angleToTarget < coneAngle)
{
hittable.RecieveHit();
}
}
}
}
Any help or adivice is much appreciated.
`