示例#1
0
 void TickUpdate()
 {
     foreach (var ent in ComSat.FindEntitiesWithinRadius(entity.position, entity.collisionRadius))
     {
         if (ent == entity)
         {
             continue;
         }
         var cr = ent.GetComponent <CollisionResponse>();
         if (cr != null && cr.layer == this.layer && !cr.fixedPosition && (canPush || !cr.canPush))
         {
             var maxDist    = entity.collisionRadius + ent.collisionRadius;
             var sqrMaxDist = maxDist * maxDist;
             var sqrDist    = (ent.position - entity.position).sqrMagnitude;
             var puntPower  = sqrMaxDist / (sqrMaxDist - sqrDist) / 2;
             var dir        = (ent.position - entity.position).normalized;
             ent.position += dir * puntPower;
         }
     }
 }
示例#2
0
    void Detonate()
    {
        if (haveExploded)
        {
            return;
        }

        haveExploded = true;
        ObjectPool.Instantiate(impactPrefab, transform.position, transform.rotation);
        var sqrRadius = explosionRadius * explosionRadius;

        foreach (var e in ComSat.FindEntitiesWithinRadius(entity.position, explosionRadius))
        {
            var sqrDist = (e.position - entity.position).sqrMagnitude;
            var power   = (sqrRadius - sqrDist) / sqrRadius;
            print("Exploding on " + e + "  sd: " + sqrDist + "  sr: " + sqrRadius + "  pwr: " + power + "  dam: " + (int)(damageAtCentre * power));
            e.Damage((int)(damageAtCentre * power));
        }
        ComSat.DestroyEntity(entity, DestroyReason.Damaged);
    }