Example #1
0
    public override void Hit(Movable mv, Vector2 direction)
    {
        // Get the list of colliders in the circle
        Vector3 mvpos = mv.GetWorldPosition();

        Collider2D[] colliders = Physics2D.OverlapCircleAll(mvpos, 2.5f);

        // Iterate through each collider
        Damagable d = null;

        foreach (Collider2D collider in colliders)
        {
            // Don't damage allies and thyself
            if (collider.gameObject.tag == gameObject.tag)
            {
                continue;
            }

            try {
                d = collider.gameObject.GetComponent <Damagable>();
            }

            catch (Exception) {
                continue;
            }

            // Get the position of the offender
            Vector2 pos = collider.gameObject.transform.position;

            // Normalize
            Vector2 dirToTarget = pos - new Vector2(mvpos.x, mvpos.y);
            dirToTarget.Normalize();

            // Get the dot product with the direction
            float angle = Mathf.Acos(Vector2.Dot(dirToTarget, direction.normalized));

            // If the other is in the telegraph
            if (angle < size)
            {
                this.score(this.onHit(d));
            }
        }
    }