Exemplo n.º 1
0
    void FireBullet()
    {
        Ray        ray = new Ray(Muzzle.position, Muzzle.forward);
        RaycastHit hit;

        Physics.Raycast(ray, out hit);

        flashLine.positionCount = 2;

        flashLine.SetPosition(0, Muzzle.position);
        flashLine.SetPosition(1, hit.point);
        flashStay         = FlashStayTime;
        flashLine.enabled = true;

        if (hit.collider)
        {
            UnitHealth  hitBody     = hit.collider.gameObject.GetComponent <UnitHealth>();
            HitCollider hitCollider = hit.collider.gameObject.GetComponent <HitCollider>();

            if (!hitBody && hitCollider && hitCollider.ColliderType == HitCollider.Type.Receive)
            {
                hitBody = hitCollider.GetOwner();
            }

            if (hitBody)
            {
                hitBody.Damage(DamagePerBullet);
            }
        }
    }
Exemplo n.º 2
0
    void OnAttackHit(HitCollider self, HitCollider other)
    {
        if (activeHit)
        {
            if (attackIsHit)
            {
                self.enabled = false;
                return;
            }

            UnitHealth owner = other.GetOwner();

            float angle = Mathf.Abs(Vector3.SignedAngle(owner.transform.forward, (transform.position - owner.transform.position).normalized, Vector3.up));

            // attacks from the back deal triple the damage
            if (angle > 90)
            {
                owner.Damage(100);
            }
            else
            {
                owner.Damage(36);
            }

            if (other.GetOwner().IsDead())
            {
                Transform chest = other.GetOwner().GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Chest);
                Vector3   force = (chest.position - transform.position);
                force.y  = 0;
                force    = force.normalized;
                force.y += 0.8f;
                force    = force.normalized;
                force   *= 200;
                chest.GetComponent <Rigidbody>().AddForce(force, ForceMode.Impulse);
            }

            attackIsHit = true;
        }
    }
    // on receive  hit play damage animation
    // and face towards enemy if attacked from the front
    void OnReceiveHit(HitCollider self, HitCollider other)
    {
        UnitHealth attacker = other.GetOwner();
        float      angle    = Mathf.Abs(Vector3.SignedAngle(transform.forward, (attacker.transform.position - transform.position).normalized, Vector3.up));

        lastDamageAngle = angle;

        if (angle < 90)
        {
            transform.LookAt(attacker.transform, Vector3.up);
        }

        if (unitHealth.Health > 0)
        {
            animator.SetTrigger("Hit");
        }
        alertTimer = AlertTime;

        AlertAlliesInRadius(AllyAlertRange);
    }