Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

ML-Agents: How to prevent friendly fire?

Discussion in 'ML-Agents' started by STALIN_CEO, Apr 3, 2021.

  1. STALIN_CEO

    STALIN_CEO

    Joined:
    Nov 2, 2017
    Posts:
    2
    I am trying to create a shooter game where a team of ML-agents targets the enemy team and kills them! I am hoping to use MultiAgent groups to split into 2 teams! The AI has to coordinate and fight against each other. I am using a RayPerceptionSensorComponent3Ds to detect the walls and the ml agents in the scene. I want to know if there is a way to detect the, lets say team id, when the raycast hits an ML-agent? This way I can give a punishment for friendly fire and reward for enemy hit! There can be different number of agents in each team so looping through and finding the distance between each agent and enemy team agent will not work! So is there any way to add another observation (example team id of raycast hit) in the rayperceptionsensor? or do I have to create unity's default raycasts and submit those in CollectObservations() ?
     
  2. ruoping_unity

    ruoping_unity

    Unity Technologies

    Joined:
    Jul 10, 2020
    Posts:
    111
    There's no obvious way to collect data other than the detectable tags in RayPerceptionSensor. To differentiate the agents on its own team or the other team, you could tag the agents on different teams with different tags. For example if you have two teams and you're only detecting the agents on the field, you could tag the agents on each team as "team_0" and "team_1". Then in the detectable tags list you put observation as is_teammate and is_enemy, which in practice will be:
    team_0_agent detectable tags: [element 0: "team_0", element1: "team_1"]
    team_1_agent detectable tags: [element 0: "team_1", element1: "team_0"]
     
    STALIN_CEO likes this.
  3. STALIN_CEO

    STALIN_CEO

    Joined:
    Nov 2, 2017
    Posts:
    2
    what if the number of teams are not fixed? how do i do it then?
     
unityunity