Beispiel #1
0
        private void OnTriggerEnter(Collider other)
        {
            if (!detectingTrigger)
            {
                return;
            }
            GameObject collider = other.gameObject;

            //Using a ray to check where is the reasl point
            if (collider.layer == LayerMask.NameToLayer("Bullet"))
            {
                Weapon.Shell shell = collider.transform.parent.GetComponent <Weapon.Shell>();
                Debug.Log("Shell hit ground!");
                Vector3 lastPosition;
                if (shell.GetUpdateNumber() == 0)
                {
                    lastPosition = shell.transform.position - 20f * shell.transform.forward;
                }
                else if (shell.GetUpdateNumber() == 1)
                {
                    lastPosition = shell.transform.position - 25f * shell.transform.forward;
                }
                else
                {
                    lastPosition = shell.transform.position - 30f * shell.transform.forward;
                }
                Ray        trajectory = new Ray(lastPosition, shell.transform.forward);
                RaycastHit hit;
                Physics.Raycast(trajectory, out hit, 30f, LayerMask.GetMask("Ground"));
                shell.SetExplosionPosition(hit.point);
                shell.HitCollier(Weapon.HitMode.Ground, 0, false);
            }
        }
Beispiel #2
0
        private void OnTriggerEnter(Collider other)
        {
            if (!detectTrigger)
            {
                return;
            }
            if (other.gameObject.layer == LayerMask.NameToLayer("Bullet"))
            {
                Debug.Log("Shell hit armor!");
                Weapon.Shell shell = other.transform.parent.GetComponent <Weapon.Shell>();
                if (shell.hit)
                {
                    return;
                }
                RaycastHit hit;
                Vector3    lastPosition = shell.transform.position;
                if (shell.GetUpdateNumber() == 0)
                {
                    lastPosition -= 20f * shell.transform.forward;
                }
                else if (shell.GetUpdateNumber() == 1)
                {
                    lastPosition -= 25f * shell.transform.forward;
                }
                else
                {
                    lastPosition -= 30f * shell.transform.forward;
                }
                Ray trajectory = new Ray(lastPosition, shell.transform.forward);
                Physics.Raycast(trajectory, out hit, 40f, LayerMask.GetMask("Tank"));
                Collider hitCollider = hit.collider;
                shell.SetExplosionPosition(hit.point);
                int      damage   = 0;
                bool     isKilled = false;
                TankPart part     = 0;
                if (hitCollider.transform.parent.CompareTag("TankWheel"))
                {
                    damage = body.Hit(TankPart.Wheel, shell.damage, out isKilled);
                    part   = TankPart.Wheel;
                }
                else
                {
                    for (int i = 0; i < ArmorColliders.Length; i++)
                    {
                        if (hitCollider == ArmorColliders[i])
                        {
                            part   = (TankPart)i;
                            damage = body.Hit((TankPart)i, shell.damage, out isKilled);
                            break;
                        }
                    }
                }
                Stats.HitInfo hitInfo = new Stats.HitInfo();
                hitInfo.hitPart      = part;
                hitInfo.totalDamage  = (byte)damage;
                hitInfo.victimSeat   = (byte)GetComponent <Tank>().seatID;
                hitInfo.attackerSeat = (byte)shell.shooter.GetComponent <Tank>().seatID;
                hitInfo.position     = shell.transform.position;

                shell.HitCollier(Weapon.HitMode.Tank, damage, isKilled);
            }
        }