Search Unity

Need advice for implementing Ai Actions

Discussion in 'General Discussion' started by MarcoMeter, Jan 27, 2016.

  1. MarcoMeter

    MarcoMeter

    Joined:
    Jun 14, 2013
    Posts:
    69
    Hello everybody,

    I'm currently implementing ai players for my hobby project called BRO. Check out these two short videos in order to get a good sense about the gameplay:

    Video A

    Video B

    Basically BRO is a multiplayer game (networking is done with Photon Bolt) with up to 8 players. The player who is in possession of the ball is chased by a drifting like beast (beast gets more accurate and faster over time until it kills someone). In order to survive you have to pass the ball to another player. Last man standing wins the match. The actions for the human players are passing the ball, moving and blinking (teleporting to any position, if the ability is not on cooldown).

    This is my very first project dealing with implementing complex ai. My goal is to implement the computer players contending each other. I don't have any issues with decision making approaches such as decision trees, state machines, neural nets, and so on. I rather experience a lack of achieving applicable actions for the ai entities.

    I would really appreciate some advice concerning implementing some specific actions.

    At first, one question:
    1. When should the ai behavior make a new decision?
    Well, so far I considered events (e.g. possession of the ball changed) and maybe some kind of scheduling. Like check for a new decision every second. But if it comes to movement, finding a new spot to go to every second doesn't really feel right. Especially because I couldn't figure out some proper algorithms to specify such spots yet. A misbehavior could end up in players kind of moving in some certain radius.

    And now about actions:

    Movement is done with Unity's NavMesh.

    1. If the ai player is not in possession of the ball, move to open space.
    The second video is pretty much the current state, featuring the implementation of a hexagon grid (Package: Grids). I'm using this grid in order to find open space. Basically each cell knows if it is occupied or not. I generate a list of cells which are not occupied. In order to shrink that list, each occupied cell's neighbors count as occupied as well. After generating that list, each ai agent samples 10 points. After that the closest point is chosen as target position. So far every second a new target point gets set for the ai player and I think it's kind of obvious that this behavior doesn't look good (behavior in video 2, the behavior in video 1 is just completely random movement).

    2. If the ai player is in possession of the ball and if the beast is not fast, move around the beast to speed it up.

    In video 2 you can see the human player making turns, so that the beast pretty much drifts around the player without harming him. So this is something to raise the chance on landing a kill as soon as you pass the ball. So I want the ai player to be able to accomplish this as well. My approach so far is to generate a bezier curve starting from the player's position to some point behind the beast. Following that bezier curve, which gets updated frequently, should achieve this goal. I tried to implement it, but probably messed up following the curve. E.g. the NavMesh agent moved to the first point and stopped, moved to the second point and stopped, and so on.... It would be really nice to discuss this approach.

    Pretty much these two actions are related to my question about when to make decisions.

    I've got some more actions on my mind, but I didn't want to work on these until I get the above ones working. So I really would appreciate advice and a discussion about my issue.
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Seems the best strategy would be to ditch the ball, then always keep an obstruction between yourself and the ball. If you can never receive the ball, then you can't die.
     
  3. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    It doesn't appear like you have implemented any steering behaviors. I'd suggest checking them out. Specifically Seek, Flee and Wander. Perhaps Pursuit and Evade as well.

    If you are using steering behaviors then play around with your forces.
     
    Kiwasi likes this.
  4. MarcoMeter

    MarcoMeter

    Joined:
    Jun 14, 2013
    Posts:
    69
    Thanks for the first replies!

    Someone has to has the ball. So there is no chance that the ball is not associated to a player.

    @GarBenjamin
    So, do you suggest to replace the NavMesh movement with steering behaviors in order to execute movement?
     
  5. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    I am not very familiar with the NavMesh. Isn't that just a way to basically be able to do obstacle collision avoidance/basic pathfinding?

    Or is it implemented as a complete system where your agents are basically under full control of the NavMesh system?

    Conceptually in my perhaps warped mind I'd not see the steering behaviors as a replacement for the NavMesh system and instead as a complement to it. Allowing you to still use the NM for overall pathfinding and obstacle intel while relying on the steering behaviors to handle the logistics of the motion.

    But again... I don't know how it is implemented or any real details about the NavMesh. On a related note I really hate it when people inplement full pre-canned all-in-one solutions. It would be great if things like the NavMesh provided different levels of functionality so a person can just use only as much as they want and use other methods for the rest. Maybe that is how it works though I dunno.
     
    Kiwasi likes this.
  6. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Have you thought of training some bots offline with with neural networks? Might work, might not. Worth a shot if you have time for it.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You estimation of NavMesh is correct. It mashes pathfinding and steering and motor into a single layer. You can force them apart, using NavMesh only to do pathfinding. But its not the way the system is set up.

    To the OP:

    For something like this I would overlay a grid on the playing area (or use the existing navmesh if you are feeling fancy). Each frame I would score each position by raycasting from the position to the player with the ball. That marks the desirability of each position. You can overlay this with a factor for the distance from the current player. The AI then uses the navmesh to move to the most favourable position.

    For the player with the ball the solution is similar. Evaluate each position for the quality of the shot, distance from the monster, and distance from the player. Move to the best position. When a shot comes up, take it.
     
    GarBenjamin likes this.
  8. MarcoMeter

    MarcoMeter

    Joined:
    Jun 14, 2013
    Posts:
    69
    This is future goal. But in order to make decisions, no matter what architecture, I have to implement the actions. This is the point where I'm struggling a lot.

    @GarBenjamin
    I'll have a closer look in to Steering Behaviors. So far I told the NavMeshAgent which point to move to. The NavMeshAgent took care about generating a path counting in avoidance.
     
  9. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    But you do have the player actions? The idea of training them to be like human players from a human data set is that you can just use the info you get to use the same controller as a human player would.
     
  10. MarcoMeter

    MarcoMeter

    Joined:
    Jun 14, 2013
    Posts:
    69
    The ai players don't have the desired actions implemented. I'm about to write my Bachelor Thesis about neural nets and it would be great to try out my neural net implementation on BRO. The risk of misbehavior would be pretty high if I would try to copy human behavior with their plain inputs.

    @BoredMormon
    What positions are you talking g about? Are you reffering to the cells of the grid? In my second video I added a hexagon grid, which I'll stick to for some crazy visualisations. It might come in handy for ai purposes. But I don't understand the approach you are describing. Do you mind providing a little sketch?
     
  11. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Sorry, I haven't actually looked at your implementation videos, just describing how I would approach it from the text. I'll check out your videos soon.
     
  12. MarcoMeter

    MarcoMeter

    Joined:
    Jun 14, 2013
    Posts:
    69
    What do you guys think about this question?

    According to this graphic, showing an example of an ai engine, (Source: Millington, Ian; Funge, John: Artificial Intelligence for games, 2009, CRC Press)
    aiengine.png
    I pretty much don't have any issues with making a decision, executing movement, providing world information, running animations and applying physics. So the only thing remaining seems to be the execution management. Well, and of course I'm struggling with implementing some actions (like finding a reasonable spot to go to). But it certainly could be a great help to have such an execution management, which is smarter than just assigning a point to go to each frame or second.

    What do you guys think?

    More general questions: Is there any recommendable open source project/game which you could reference?
    I occasionally come across recommendations for aigamedev.com. I'm not exactly sure if a membership is worth it. Has anybody some feedback about the content of the premium stuff on aigamedev.com?
     
  13. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    When situation changes. As we can't predict when player changes situation in realtime game, we should check each time interval if situation has changed. Time inteval depends on pacing of your game: it can be each frame, quarter of second, second, turn, it can even be 5 seconds for slow games...

    About that game: 90% of your A.I. logic can be made using steering behaviours. So your game can easily live with simplest A.I. which only changes source of avoidance when ball changes hands and changes into trying to trap someone if you have ball (while not being caught). Besides there's only 2 tactics possible: don't hit by ball(get cover behind someone else?) and get wolf to come to your target and then pass ball to that poor soul. Both are easily calculatable in vectors math so steering behaviours will do it for you (with only slight corrections from higher-level A.I. logic) and counteraction algorithm is quite easy too so this game is best with hard-coded A.I. unless you complicate it a lot with features later.
    As for desired actions - here they are far too simple. We have "Avoid being hit", "Avoid monster", "Follow someone", "Hide behind someone"... All of those are movement which can be done with steering behaviours. Even "Make monster come to someone" can be done using simple vector math and steering behaviours.
     
    GarBenjamin likes this.
  14. MarcoMeter

    MarcoMeter

    Joined:
    Jun 14, 2013
    Posts:
    69
    Alright, steering behaviors seem to be a reasonable approach. I'll start the implementation next week and will loop you in if something gets done.