def get_ball_contacts()

in gym-compete/gym_compete/new_envs/kick_and_defend.py [0:0]


    def get_ball_contacts(self, agent_id):
        mjcontacts = self.env_scene.data._wrapped.contents.contact
        ncon = self.env_scene.model.data.ncon
        contacts = []
        for i in range(ncon):
            ct = mjcontacts[i]
            g1 , g2 = ct.geom1, ct.geom2
            g1 = self.env_scene.model.geom_names[g1]
            g2 = self.env_scene.model.geom_names[g2]
            if g1.find(six.b('ball')) >= 0:
                if g2.find(six.b('agent' + str(agent_id))) >= 0:
                    if ct.dist < 0:
                        contacts.append((g1, g2, ct.dist))
        return contacts