multiagent-particle-envs
multiagent-particle-envs copied to clipboard
bug in is_collision function
I am referring to the following function:
def is_collision(self, agent1, agent2): delta_pos = agent1.state.p_pos - agent2.state.p_pos dist = np.sqrt(np.sum(np.square(delta_pos))) dist_min = agent1.size + agent2.size return True if dist < dist_min else False
As I understand it, the above code is supposed to detect when an agent collides with another agent. However, it currently returns false positives when an agent "collides with itself". This is because the calling function passes the same agent entity in for agent1 and agent2 periodically within its loop.
In my fork, I have included the following lines of code to fix the bug:
if agent1 == agent2: return False
So the code now reads:
def is_collision(self, agent1, agent2): if agent1 == agent2: return False delta_pos = agent1.state.p_pos - agent2.state.p_pos dist = np.sqrt(np.sum(np.square(delta_pos))) dist_min = agent1.size + agent2.size return True if dist < dist_min else False
Please let me know if I have misunderstood something. Thanks :)