(self, physics, unused_random_state)
Resolve contacts and update ball-player contact trackers.
Resolve contacts and update ball-player contact trackers.
Resolve contacts and update ball - player contact trackers .
def after_substep(self, physics, unused_random_state):
    """Resolve contacts and update ball-player contact trackers."""
    if self._hit:
      # Ball has already registered a valid contact within step (during one of
      # previous after_substep calls).
      return

    # Iterate through all contacts to find the first contact between the ball
    # and one of the registered entities.
    for contact in physics.data.contact:
      # Keep contacts that involve the ball and one of the registered entities.
      has_self = False
      for geom_id in (contact.geom1, contact.geom2):
        if geom_id == self._geom_id:
          has_self = True
        else:
          player = self._geom_id_to_player.get(geom_id)

      if has_self and player:
        # Detected a contact between the ball and an registered player.
        if self._last_hit is not None:
          self._intercepted = player.team != self._last_hit.team
        else:
          self._intercepted = True

        # Register repossessed before updating last_hit player.
        self._repossessed = player is not self._last_hit
        self._last_hit = player
        # Register hit event.
        self._hit = True
        break
def after_substep ( self , physics , unused_random_state ) : if self . _hit : # Ball has already registered a valid contact within step (during one of # previous after_substep calls). return # Iterate through all contacts to find the first contact between the ball # and one of the registered entities. for contact in physics . data . contact : # Keep contacts that involve the ball and one of the registered entities. has_self = False for geom_id in ( contact . geom1 , contact . geom2 ) : if geom_id == self . _geom_id : has_self = True else : player = self . _geom_id_to_player . get ( geom_id ) if has_self and player : # Detected a contact between the ball and an registered player. if self . _last_hit is not None : self . _intercepted = player . team != self . _last_hit . team else : self . _intercepted = True # Register repossessed before updating last_hit player. self . _repossessed = player is not self . _last_hit self . _last_hit = player # Register hit event. self . _hit = True break