Search Unity

[TheFly]Pointless freely wandering ai

Discussion in 'Works In Progress - Archive' started by Tomnnn, Nov 24, 2014.

  1. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I'm working on a horror game. I believe that part of horror includes having an unpredictable creature and a suspenseful atmosphere. To combine the two, I've begun the process of developing a silly and random path generation system. I'm having some trouble coming up with a title for it, so for now I'm just calling it the "TheFly" because it reminds me of a fly buzzing around a room.

    I have coded a series of patterns for a 'fly' to follow, and during points of their travel, they will attempt to generate path nodes for the ai to follow. It's going to fail quite often. I am loving the results so far. Sometimes the ai has a path within 30 seconds, but the longest I've seen was 3 minutes and 8 seconds xD

    Instead of building an ai with jittery motion, I've built an invisible jittery object to create strange paths for the ai to take. After all of the path nodes are set, the fly goes back to the ai and sets itself to 'done'. At that point, when the ai decides it would like to move, it checks the public 'points' variable the fly has spent who knows how long generating it - and then may decide to dismiss those points and have the fly try again later! The amount of arbitrary dismissal and idle time is to create a more believable end result - an ai that is mimicking a very broken and bug ridden robot :)

    Various sound and light cues coming from the robot will be to inform the player what's happening. Is the robot seizing slightly with flashing eyes? It's looking for a path! Do you enter the room? The robot might finish at any time! ...or it might take a few minutes.

    Check it out once it's done processing :D



    Aww look at the path it made in almost 2 minutes! It's almost time to make it walk. They grow up so fast.
    Screen Shot 2014-11-24 at 12.40.55 PM.png
     
    Last edited: Nov 24, 2014
  2. Skorn

    Skorn

    Joined:
    Oct 31, 2014
    Posts:
    22
    This was something I was looking for in my horror game. Do you have any other news on this or anything?
     
  3. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Of course :D I have a lot of variables in it now that tweak how many nodes it tries to make and how much distance between them there needs to be. This will greatly effect how it moves.

    allowed misses: low
    nodes to make: low
    distance between nodes: low

    This will produce short moves often

    allowed misses: high
    nodes to make: low
    distance between nodes: medium

    This will produce longer moves fairly often

    Allowed misses: high
    nodes to make: medium
    distance between nodes: medium

    This will take 3+ minutes to run, and you'll end up with a much longer path

    If you want just path finding, I recommend A*. I'm designing this ai to realistically wander :)
     
    Skorn likes this.
  4. Skorn

    Skorn

    Joined:
    Oct 31, 2014
    Posts:
    22
    Thanks for the reply! I'll surely take that into consideration. I've been working on 3d modeling for past couple months and haven't been programming as much as I would like to.

    I would love to hear more about how this works and possibly see it in action with more details. :):)
     
  5. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I'll make a video sometime tomorrow probably.

    I'm almost done with the demo part of the game. The idea for the 'demo' is going to be collect all of the tools and repair the 'robot'. I modeled some tools today and will be putting them in the game tomorrow to be collected. Once all of the tools & a spare part are collected, the user must locate the robot and wait for it to go idle. If the user can approach the robot and interact with it while it is idle, while having all of the needed parts, the robot will be fixed and no longer be a threat. If the robot moves when the player is close, the player will lose.

    There will be much more to the game eventually, but to have a demo by mid december, that's going to be the game.

    As for the ai part you're probably more interested in, there are a few tweaks left to be done, and then I'll put this project & the source of it in the showcase. The basic idea of the system is...

    1 - Send out a jittery little object, because moving an object in space is cheap and easy to do, with there being little work besides adding some movement to the transform of the object
    2 - for the first node, check if the object can see the ai to be moved
    3 - for all nodes after the first, check if the object can see the previously placed node

    If the ai reaches it's goal for nodes to be placed, give them to the ai. Because of how the nodes were placed, the ai can traverse them in order without anymore calculations. Additional calculations can be done to cut out redundant nodes that make the ai wander back and forth, but the seemingly random and arbitrary motions are the point :D

    This ai will be ideal for any game where your enemy is very dumb and or blind or is mechanical yet very broken.
     
  6. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I have done something magnificent. I have added anxiety and laziness to my ai! The 'idleness' variable builds up over time, increasing the ai's likeliness to move. Once it actually begins moving, however, it's desire to move decrements by the amount of moves left to make. It's now as lazy and anxious as your average anxious and lazy person :)

    Code (CSharp):
    1. /*Arbitrarily adjust values*/
    2.     void adjustVariables()
    3.     {
    4.         /*if the fly is inactive*/
    5.         if(!usefly && fly.GetComponent<flyscript>().done && Random.Range(0,100) > 98-idleness)
    6.         {
    7.             usefly = true;
    8.         }
    9.         /*if the fly is inactive and we have no points*/
    10.         else if(local_loc.Count == 0)
    11.         {
    12.             if(idleness < 100)
    13.             {
    14.                 idleness++;
    15.             }
    16.         }
    17.         /*if we have no more points yet the fly is full, we need more points & can use the fly again*/
    18.         if(usefly && local_loc.Count == 0 && fly.GetComponent<flyscript>().points != null)
    19.         {
    20.             fly.GetComponent<flyscript>().points = null;
    21.             fly.GetComponent<flyscript>().fly_state = 0;
    22.         }
    23.         /*if the fly is inactive, but the robot is active.
    24.         count>0 : do not seek the player while idling
    25.          */
    26.         if(fly.GetComponent<flyscript>().done && local_loc.Count > 0)
    27.         {
    28.             /*check if we can see the player & actually reach the player*/
    29.             if(canMove(MainScript.thisInstance.player.head.transform.position))
    30.             {
    31.                 /*try to get to the player*/
    32.                 local_loc.Clear();
    33.                 local_loc.Add(new Vector3(MainScript.thisInstance.player.head.transform.position.x,
    34.                                           0.5f,
    35.                                           MainScript.thisInstance.player.head.transform.position.z));
    36.             }
    37.         }
    38.  
    39.         /*if there are points to use*/
    40.         if(local_loc.Count > 0 && idleness-local_loc.Count > 0)
    41.         {
    42.             /*gradually reduce the desire to move based on current planned movements*/
    43.             idleness-= local_loc.Count;
    44.         }
    45.     }//adjust variables
     
    Skorn likes this.
  7. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Here's the shortened demo. It's basically slenderman now haha. I should have some new models and levels to work with over the weekend, but the development will have a short stop here for the time being.