Ejemplo n.º 1
0
        // this should be called only from other vehicles
        void IVehicle.Collide(IVehicle otherVehicle, VehicleCollisionInfo info)
        {
            if (Health == 0)
            {
                return;
            }

            float damage = info.Damage;

            // receive damage
            if (damage > 0)
            {
                // receive damage
                ReceiveDamage(Damage.CreateBulletDamage(
                                  damage, -Vector3.forward, info.CollisionPoint, info.CollisionNormal, info.Initiator));
            }

            // collide other with this, player don't send them damage
            var backInfo = new VehicleCollisionInfo();

            backInfo.ThisWithOther   = false;
            backInfo.Initiator       = Player.gameObject;
            backInfo.CollisionPoint  = info.CollisionPoint;
            backInfo.CollisionNormal = -info.CollisionNormal;

            otherVehicle.Collide(this, backInfo);

            // call event even if damage == 0
            OnVehicleCollision(otherVehicle, damage);
        }
Ejemplo n.º 2
0
        void OnCollisionEnter(Collision col)
        {
            var other = col.collider.GetComponent <IVehicle>();

            if (other != null)
            {
                VehicleCollisionInfo info = new VehicleCollisionInfo();

                // if driver is still alive,
                // then send full damage,
                // otherwise nothing
                info.Damage = State == EnemyVehicleState.Active ? data.CollisionDamage : 0;

                // set to true as other vehicle must call 'Collide' method
                // on this one with other data
                info.ThisWithOther = true;

                info.Initiator = gameObject;

                // there is always at least one contact,
                // so this check is unnecessary
                if (col.contacts.Length > 0)
                {
                    info.CollisionPoint  = col.contacts[0].point;
                    info.CollisionNormal = col.contacts[0].normal;
                }

                other.Collide(this, info);
            }
        }
Ejemplo n.º 3
0
        public void Collide(IVehicle other, VehicleCollisionInfo info)
        {
            ReceiveDamage(Damage.CreateBulletDamage(
                              info.Damage, Vector3.forward, transform.position, Vector3.up, null));

            if (info.ThisWithOther)
            {
                VehicleCollisionInfo backInfo = new VehicleCollisionInfo();
                backInfo.Damage = State == EnemyVehicleState.Active ? data.CollisionDamage : 0;

                // don't process it on other side (to prevent loop)
                backInfo.ThisWithOther = false;

                backInfo.Initiator = gameObject;

                backInfo.CollisionPoint  = info.CollisionPoint;
                backInfo.CollisionNormal = -info.CollisionNormal;

                other.Collide(this, backInfo);
            }

            DoVehicleCollision(info.Initiator);
        }