Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Make my agent not to attack from afar

Discussion in 'ML-Agents' started by ariel7590, May 20, 2022.

  1. ariel7590

    ariel7590

    Joined:
    Oct 12, 2018
    Posts:
    4
    Hello guys,
    I'm using ML-agents for my fighting game.
    I made a script called AI that has an integer variable called actionNum.
    My agent script, in the method OnActionReceived takes that variable and puts random integers in it (from 0 to 8 which is the number of the actions that my fighter can do so far).
    I have another script called Actions that has the methods of the actions themselves and a method called IntToAction that takes an integer and goes to one of the methods via switch case.
    The Ai script, in the Update method, always activates this IntToAction method.
    So far, my agent works but it's attacking randomly without considering the distance from the player.
    I tried putting the distance as an observation and giving a negative reward if my agent attacks from a huge distance but after 10-15 minutes of training, my agent stopped attacking entirely and just started to walk forwards and backwards.
    I would love for some advice on how I can teach the agent to attack only when he is close to the player.
    Thnx in advance.