Search Unity

Assets Combat Vehicle AI - Tanks

Discussion in 'Works In Progress - Archive' started by SkyYurt, Oct 20, 2018.

?

Do you need AI for Combat Vehicles in your Game?

  1. I need it

    16 vote(s)
    88.9%
  2. I don't need it

    1 vote(s)
    5.6%
  3. I'm interested, but don't need it

    1 vote(s)
    5.6%
  4. I don't know

    0 vote(s)
    0.0%
  1. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    Game AI for Combat Vehicles

    Hi Guys!
    I want to present an AI Project that i'm currently working on, which is planned to be released on the Asset Store.

    Video




    The Goal
    The goal of this project is to develop an AI that can be used for combat vehicles of any kind in games. Moreover, it is to develop the AI in a way to make it easy to customize and add new behaviors as needed.

    Description
    The AI is build using a Behavior System, separating the system itself and the behaviors, making it easier to make new actions for the AI and add them to the behaviors of the individual AI units.

    The Combat Vehicle AI will come with following predefined behaviors:
    1. Combat
      • Locate and Fight targets (example shown in Video section above)
      • Advance towards enemy units (example shown in Video section above)
      • Seek safe spots and Retreat when taken too much damage (example shown in Video section above)
      • Tactics, e.g. flank enemies and try to position itself behind them.
      • Team Combat, e.g. If the AI can't see targets, team members will help them locate enemies. (example shown in Video section above)
    2. Objective Behavior (behaviors executed when no enemy around to fight)
      • Move towards specified objective positions.
      • Guard position
      • Patrol on predefined path.
    The package will come with a bunch of combat vehicles and their corresponding AI, which all will be game-ready (However, this package will focus on AI, so the 3D models will be simple).

    What do You need in an AI package like this?
    Feedback and comments are appreciated.
    I am very interested to know what you expect from this package and which features (or behaviors) could make it even better, so that I can implement them before releasing to the Asset Store.

    Thanks

    - Muhsin Kaymak
     
  2. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    Tactics: Flanking Enemies



    Whenever the AI gets the chance (and their flanking cooldown is over), they will calculate a path for performing a flanking maneuver against the target. The video above shows flanking behavior on different environments.
     
  3. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    A simple to implement, but a very necessary requirement of intelligent vehicles is that the AI is aware of their surroundings. It is important the that vehicles don't bump into friendly vehicles while following the navigation path.

    Our Combat Vehicles use the Unity NavMesh to navigate on the levels, and it can sometimes be difficult to control how the agents behave while following a path.
    This is why we decide to use a hybrid and compine the Unity NavMesh and standard pathfinding, which allowed us to implement features like flanking enemies (see video in post above) and basic avoidance of friendly units:



    These tanks follow the exact same path, but with collision detection they are able to avoid hitting or overlapping each other.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Why AI shooting into wall?
     
    SkyYurt likes this.
  5. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    Aiming bug :) The AI fired as soon as it was able to raycast the target, but the turret was rotated towards the wall, so the missile hit that.

    Will make sure AI's turret is rotated towards the target before firing. Thanks for the feedback :)
     
    Antypodish likes this.
  6. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    First Gameplay Demo

    I have prepared a short demo game to showcase the current state of the AI. I plan to prepare more of these game demos as the development progresses.

    You can download the demo from:
    https://sanjak.itch.io/combat-vehicle-ai

    The demo showcases following behaviors of the AI tanks:
    • Advancing towards target
    • Retreating and hiding
    • Evading projectiles
    • Flanking targets
    • Seeking out last known position of targets
    • Team based battle

    And if you don't want to download and play the demo, you can watch this video showcasing the same level:


    I need all the feedback I can get, so I will really appreciate it if you could take the time to try out the demo and tell me your thoughts and ideas.

    Thanks!

    Muhsin Kaymak
     
    Last edited: Nov 1, 2018
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Nice,
    One thing I think is missing, is aiming target position prediction, when AI aims for moving target and fires.
    Seams AI missing on that cases.
     
    SkyYurt likes this.
  8. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    Added to my to-do list. Thanks :)
     
    Antypodish likes this.
  9. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    Objective 1: Patrol Path

    Today I want to show you the first part of the objective system.
    When no enemies are around to fight, the AI will perform various tasks assigned to them. These tasks are called objectives.
    You build a list of objectives for the AI, which the AI will deplete by performing each objective one by one.

    The first objective i want to show is the Patrol Path objective:


    You are able to design a patrol path for the AI, in the Unity Scene View, and make them patrol it. When the AI reaches the objective 'Patrol Path', they will first validate the path to make sure that the path doesn't go through walls, and then they will begin patrolling through it (we can see in the video that the AI makes an alternative path to avoid going through walls).

    The AI will patrol the path and then continue to the next objective on the objectives list.
    However if you mark the patrol path as a looping path(as shown in video), the AI will continuously patrol through the path, making it ideal for enemies that just needs to patrol the same path until attacked.
     
  10. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    Objective 2: Guarding Position

    Assigning the Guarding Position Objective to the AI will make them stand their ground and wait for enemies to appear.
    This Objective is also the default objective, so if no other objectives is assigned to the AI, they will automatically perform a guarding behavior.

    Whenever the AI begins the guarding behavior, they will first determine possible directions the enemy can appear from. This is done using raycasting:
    Capture_guard.PNG

    You are able to adjust how many raycasts used per unit.

    Capture_guard_2.PNG

    After getting the possible directions, the AI will begin cycling through these and turn their turret towards them

    GIF:
    guading_gif.gif

    Video:
     
  11. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    Movement Prediction is now implemented as requested.

    aim.PNG

    Green line shows where the AI predicts the target will be at, when the projectile impacts, and aligns its barrel accordingly, making a perfect hit.


    Current Progress

    fire_aim3.PNG

    Last week I started testing with other models from the Assets Store, to make sure that the AI works universally on all kind of 3D assets and to detect possible problems that may occur.
    No major issues detected, however I did notice that different models can have different axis's. Forward on one model might not be forward on another.
    I will write a small step by step guide in the documentation on how you can eliminate this problem.

    I also began testing on Terrains, which is why I haven't posted in a week :D
    I had many problems with physics and the precision of the AI's aim, while testing on Terrain. Both problems has since been fixed :)
    The Aiming problem was simply math formulas that needed to be adjusted to be better at calculating the angle of the barrel.
    For the Physics problem I decided to remove the AI's rigidbody component altogether and make my own way of calculating how the AI should interact with the environment.
     
    FusionSticc and Antypodish like this.
  12. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Nice

    And well done. A little bit extra to game play ;)
     
    SkyYurt likes this.
  13. FusionSticc

    FusionSticc

    Joined:
    Mar 16, 2014
    Posts:
    49
    Some awesome stuff going on! Can't wait for more updates.

    Cheers!
     
    SkyYurt likes this.
  14. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    Thank you! I really appreciate the support :)
     
    FusionSticc likes this.
  15. abcarroll3

    abcarroll3

    Joined:
    Jun 12, 2017
    Posts:
    7
    Was this ever released?
     
  16. SkyYurt

    SkyYurt

    Joined:
    Dec 12, 2010
    Posts:
    234
    No unfortunately