Search Unity

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.