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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

AI strategies

Discussion in 'Scripting' started by Boz0r, Aug 19, 2016.

  1. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    I was thinking about AI, and how to do more complex behaviour than just shortest path stuff.

    How would you make racing AI, where you had to account fo acceleration and braking, hitting turns the correct way, that sort of thing?

    What about raptor behaviour, where two raptors attack from the sides, and one from the front?

    Any ideas?
     
  2. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    Any AI is very easy once you nail the architecture. As long as you keep it as simple as possible!

    For a racing AI I would say you use something called Utility Theory. Its an easy concept. You collect all the necessary info, so speed, distance from obstacles and the car's info like acceleration and brake time. A utility AI would then compare all these and then decide what is the best action.

    Say you have a low turning circle and someone crashes infront of you. You would quikly calculate in your head that you have to slow down, since your turning is too slow to go around. The AI would do the same. And if you had a much better turning circle, and could drive around without slowing down much, you would.

    I found this really quick, since I can't provide a practical example: https://www.assetstore.unity3d.com/en/#!/content/8967

    As for following the road, I would just cheat in this case. Place some waypoints along the track, and generate a spline between them, being the optimal route they try to follow, and a spline from the AI to the next couple of waypoints that they would actually follow, so they wouldn't turn really sharp to go through a waypoint.

    As for the raptors, I have done this before and what architecture you use does not really matter. For this you want to use a blackboard. A script that isn't attached to any AI, but helps to control multiple. The blackboard should select the best suited raptors, and select a position based on distance and angle.

    What I did was really quite clever if I may say so myself. Ofcourse I didn't come up with it hehe. The AI used A* pathfinding, which places nodes all over the map. Each of these nodes were assigned a number every other second. For example:
    0 - This node is fully visible to the player.
    1 - This node has ducking cover
    2 - This node has full cover
    3 - This node has full cover and good peeking position for shooting
    4 - This node is behind the player
    5 - This node is behind the player and has cover

    And on. (I really assigned them a sort of binary code in the end. 011 would be node behind player, with cover, when standing and sitting etc)

    With these nodes I already had possible positions, so the blackboard would get some nodes on each side of the player, or behind the player based on how many AI 'Raptors' were available. Then select the closest ones that fit this criteria (to side of player, and with cover) and send the raptors here. Also avoid nodes that are fully visible infront of the player!

    There are plenty of ways to do this, regardless of architecture or pathfinding system. You just have to work with what you've got. Think simple and it usually becomes simple! Sorry for this long post but I rarely see anyone interested in AI on this forum :)
     
  3. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    I also made this really bad thread a while ago: http://forum.unity3d.com/threads/ad...tificial-intelligence-tutorial-series.350062/

    Its poorly written but its a really good intro to advanced AI, just programming wise. It uses my asset Simple Option Stacker, which is a Stack-based Finite State Machine, just a really good all purpose architecture, but you can skip that and just look at the blackboard stuff. The last proper post.

    ~ Angelo
     
  4. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    Those are some really good ideas, I'll be sure to read your other thread.

    I think AI is a really interesting area, and I've always wanted to make an ecosystem simulation, with animals, weather, all sorts of crap, but I don't have the time :(.

    My goal is to have the AI without the need for a waypoint graph, and other sorts of preparation. I found an article on motion planning for robotic race cars, that I think may have some good info.
     
  5. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    That sounds cool. I remember some guy tried to do the same ecosystem thing a while back, only with people and jobs only. Sure, this guy got a lot of flak for being an asshole.. I linked the thread because I think its a cool idea, not because its useful :p

    Anyways I love making anything more generic, especially AI. Anything you can do to make the design/setup face easier! Unfortunatley I have never even attempted to do a racing AI, so I don't know much on the subject. I'll still be sure to check out that article, it sounds interesting indeed.