예제 #1
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (!isInvul && !collision.collider.gameObject.CompareTag("Armor"))
     {
         ContactPoint2D contact         = collision.contacts[0];
         float          dotImpact       = Mathf.Abs(Vector2.Dot(contact.normal, collision.relativeVelocity));
         Rigidbody2D    otherColliderRB = collision.rigidbody;
         Time.fixedDeltaTime = initialDeltaTime * Time.timeScale;
         float sumImpact    = dotImpact;
         float colliderMass = 9999;
         if (otherColliderRB)
         {
             colliderMass = otherColliderRB.mass;
             float speedMult   = 0.2f;
             float speedImpact = Mathf.Sqrt(Vector2.SqrMagnitude(otherColliderRB.velocity - collision.otherRigidbody.velocity));
             if (otherColliderRB.sharedMaterial)
             {
                 speedMult = otherColliderRB.sharedMaterial.friction * 2;
             }
             sumImpact += speedMult * speedImpact;
         }
         if (collision.collider.gameObject.CompareTag("Weapon"))
         {
             sumImpact += 7;
         }
         if (health == 1)
         {
             // low health slightly less likely to instadie
             sumImpact -= 3f;
         }
         if (sumImpact > 9f)
         {
             health--;
             // always trigger slowmo with the special 0.031415f time.
             Time.timeScale      = 0.0123f;
             Time.fixedDeltaTime = initialDeltaTime * Time.timeScale;
             if (health == 1)
             {
                 isInvul      = true;
                 timeOfInjury = Time.time;
                 turningRed   = true;
                 currentEngineScript.setCoreTurnMult(4f);
                 currentEngineScript.setCoreMoveMult(4f);
             }
             else if (health <= 0)
             {
                 // blow up, explode
                 WeaponControl WControl = this.transform.parent.GetComponent <WeaponControl>();
                 if (WControl && WControl.hasWeaponEquipped())
                 {
                 }
                 this.transform.parent.gameObject.SetActive(false);
                 for (int i = 0; i < 30; i++)
                 {
                     GameObject pc = Instantiate(gibPiece, this.transform.position, this.transform.rotation);
                 }
             }
         }
     }
 }