Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

artificial intelligence Bomberman

Discussion in 'Scripting' started by dikker, Dec 17, 2013.

  1. dikker

    dikker

    Joined:
    Nov 28, 2013
    Posts:
    3
    Hi, i have a problem and i hope the unity community can help me.
    I want to make an artificial intiligence script but i don't know how to do it.
    The AI will try to kill my player and if there is a cube wich blocks him, the AI must destroy it and hide him self if is it possible or roll away a distance from the bomb.
    Thanks in advance
    (PS: sorry for my english i'm french:D)
     
    MichaellMunayco likes this.
  2. Vevusio

    Vevusio

    Joined:
    Oct 13, 2013
    Posts:
    22
    i would check this out: https://www.assetstore.unity3d.com/#/content/6563

    it looks pretty powerful and is free, but probably takes some getting used to

    the basic approach would be something like this pseudo code

    Code (csharp):
    1.  
    2. while(true) {
    3.     // get all objects in front of agent
    4.     objectsHit = Physics.RaycastAll( agentPosition, agentLookAhead )
    5.     // if the player is not somewhere in front of agent
    6.     if( objectsHit !contain Player) {
    7.         // move agent around and check again
    8.         continue;
    9.     }
    10.     // the player is in front of agent, leave the loop
    11.     break;
    12. }
    13. // get the nearest object in front of agent
    14. lookAtObject = Physics.Raycast ( agentPosition, agentLookAhead )
    15. if( lookAtObject is Player ) {
    16.     // agent is looking directly at player, go kill him
    17. }
    18. else if( lookAtObject is cube ){
    19.     // a cube is blocking the way to player, go bomb it
    20. }
    21. else {
    22.     // something else is blocking the way
    23. }
    24.  
     
  3. dikker

    dikker

    Joined:
    Nov 28, 2013
    Posts:
    3
    Thank you
     
  4. dikker

    dikker

    Joined:
    Nov 28, 2013
    Posts:
    3
    Hi, thank you for answering to my quetion but i have another one ^^. How my ennemy can roll away from the bomb and how can my ennemy can find a safe place.
    Thanks a lot for your help and your time.
    (PS can you allow private message please?)
     
  5. Eyeshock

    Eyeshock

    Joined:
    Sep 7, 2012
    Posts:
    60
    You want to read up on finite state machines; literally any action you describe will come down to a trigger/event, new state, new target, pathing.

    (ex. detect nearby bomb via trigger, new state is retreat, new target is closest safe zone, move to safe zone, reach safe zone: new state is search).

    This guy (link below) does some rudimentary state machine AI. For the pathing I'd recommend A*, or any of the numerous AI libraries for free on the asset store; alternatively you could look into behavior trees, but I think state machine will be simpler and sufficient for your game.
    http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial