// 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); }
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); }