private void OnCollisionEnter2D(Collision2D collision)
    {
        // First contact with platform.
        if (collision.collider.CompareTag("Platform"))
        {
            this.platformCollider = collision.collider;
            this.enemyOffset      = (Vector3)this.enemyRB.position - this.platformCollider.bounds.center;
        }

        else if (collision.collider.CompareTag("Player"))
        {
            switch (CollisionUtilities.GetCollisionPosition(collision))
            {
            // Player hit the enemy on the top of the enemy's collision box.
            case CollisionUtilities.CollisionPosition.TOP:
                this.PlayerJumpOnHead(collision.gameObject);
                break;

            // Player hit on side.
            case CollisionUtilities.CollisionPosition.LEFT:
            case CollisionUtilities.CollisionPosition.RIGHT:
                this.StunPlayer(collision.gameObject);
                break;
            }
        }
    }
Esempio n. 2
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     switch (collision.gameObject.tag)
     {
     case "Player":
     case "Enemy":
         if (CollisionUtilities.GetCollisionPosition(collision) == CollisionUtilities.CollisionPosition.TOP)
         {
             collision.transform.parent = this.transform;
         }
         break;
     }
 }
Esempio n. 3
0
 protected void OnCollisionStay2D(Collision2D collision)
 {
     switch (collision.gameObject.tag)
     {
     case "Platform":
     case "Player":
         if (CollisionUtilities.GetCollisionPosition(collision) == CollisionUtilities.CollisionPosition.BOTTOM)
         {
             this.grounded = true;
         }
         break;
     }
 }
Esempio n. 4
0
 private void OnCollisionStay2D(Collision2D collision)
 {
     if (
         collision.gameObject.CompareTag("Platform") &&
         CollisionUtilities.GetCollisionPosition(collision) == CollisionUtilities.CollisionPosition.BOTTOM &&
         CollisionUtilities.FullyContactingPlatform(collision.collider.bounds, this.playerCollider.bounds, 0.25f)
         )
     {
         if (collision.collider != this.lastPlatformCollider)
         {
             this.lastPlatformCollider = collision.collider;
         }
         this.lastOffset = this.transform.position - this.lastPlatformCollider.bounds.center;
     }
 }