Ejemplo n.º 1
0
 /// <summary>
 ///  Handle actions related to specific stomp collisions
 /// </summary>
 private void _handle_stomp_collisions()
 {
     // Loop on all collisions when MoveAndSlide() is called for this frame
     for (int i = 0; i < GetSlideCount(); i++)
     {
         KinematicCollision2D collision = GetSlideCollision(i);
         Godot.Object         collider  = collision.Collider;
         if (collider.GetScript() != null)
         {
             bool is_stomping = (
                 IsOnFloor()
                 // If the collision comes from (aproximatly) above from an angle perspective
                 && collision.Normal.Dot(Vector2.Up) > 0.7f
                 );
             if (is_stomping && collider is I_StompBouncible)
             {
                 _velocity.y = -(collider as I_StompBouncible).stomp_bounce_impulse;
                 if (collider is Enemy)
                 {
                     (collider as Enemy).die();
                 }
             }
         }
     }
 }