"AI system" (Ver.2.5) (Updated)

(Warning.)
Do not change their names and hierarchies.



(Outline)
AI system is based on Unity's Navigation function, and requires Navigation Meshes (NavMesh) in the scene.

In the demo scenes, the NavMesh is already prepared.
If you want to bake NavMesh for your scene, please refer to the following Unity official manual.
http://docs.unity3d.com/Manual/Navigation.html

AI system is composed of three objects "AI_Core", "AI_Eye" and "AI_Hand".

"AI_Core" is the main object that controls the driving and the firing.
"AI_Eye" is used for searching the target.
"AI_Hand" is used for detecting an obstacle in front of the tank.

AI tank patrols while passing the specified WayPoints in 'Search Mode'.
In 'Search Mode', AI tank runs while casting a Ray (Ray_1) from the "AI_Eye" to the target decided by "Game_Controller" in the scene.
When the Ray hits against the target, the action mode is shifted to 'Chase Mode'.
In 'Chase Mode', AI tank chases the target while casting another Ray (Ray_2) from the "Bullet_Generator" to the target.
When the second Ray hits against the target, the AI gives order to fire.
The action mode returns to 'Search Mode' when the target is destroyed, or when the specified time passes after the AI loses sight of the target.


The commonly used options for AI can be set from the "Top object of tank " or "Event_Controller".
And please read also "How to use AI tank".


*** AI_Core ****

"AI_Core" is the main object of AI system operated by "AI_CS (Script)" and "Nav Mesh Agent".
"AI_CS (Script)" controls the driving and the firing while following the "AI_NavMeshAgent_Object".

You can find some options in the Inspector window.

"AI_CS (Script)"

(Drive Settings)
    [WayPoint Radius]
    Set the allowable range of each waypoint.
    When the AI tank enters this range, the AI updates its destination to the next waypoint.

    [Pivot Turn Angle]
    The tank does pivot-turn (swivel turning) when the angle to the next corner is greater than this value.
    (Notice.)
    When your AI tank has trouble turning a tight corner, try to reduce this value.


    [Min Target Angle]
    The tank goes straight on when the angle to the next corner is smaller than this value.

    [Min Turn Rate]
    [Max Turn Rate]
    AI calculates the turning rate within this range.
    Usually you need not to change these values.

    [Min Speed Rate]
    AI decreases the tank speed while turning by referring to this value.
    (Notice.)
    When your AI tank has trouble turning a tight corner, try to reduce this value.


    [Max Speed Rate]
    You can adjust the maximum speed of the tank by changing this value.

    [Slow Down Range]
    AI decreases the tank speed as it approaches the next corner within this distance range.

    [NavMeshAgent Prefab] (New)
    Set a prefab having "Nav Mesh Agent" component.
    You can find the prefab "AI_NavMeshAgent_Object" in the 'Tank_Components' folder.
    Assets >> Physics Tank Maker >> Prefabs >> Tank_Components
    (Notice.)
    AI navigation system has been changed in version 2.5.
    "AI_NavMeshAgent_Object" is spawned at the starting, and it leads the AI tank.

   

    [Agent Distance] (New)
    The distance that the "AI_NavMeshAgent_Object" tries to keep from the tank.

    [Agent Additional Distance] (New)
    The distance added to the "Agent Distance" according to the tank speed.
    (Notice.)
    When your AI tank fails to turn a corner at high speed, try to increase this value.


    [Obstacle Prefab]
    Set a prefab having "Nav Mesh Obstacle" component.
    You can find the prefab "AI_Obstacle_Object" in the 'Tank_Components' folder.
    Assets >> Physics Tank Maker >> Prefabs >> Tank_Components

    [Stuck Count]
    AI changes its destination when this time period passes after the tank had been stuck at any obstacle.


(Combat Settings)
    [Direct Fire]
    When the tank has a high-angle gun such as a howitzer, disable this option.

    [Fire Angle]
    AI gives order to fire only while the direction of the gun is within this angle range from the ideal direction to the target.

    [Fire Count]
    AI gives order to fire when this time period passes after the gun keeps the "Fire Angle" to the target.
    (Notice.)
    When the gun is a machine gun, set this value to zero.



*** AI_Eye ***

This object must be placed under "AI_Core" in the hierarchy.
AI system casts a Ray from this object in order to search the target.
(Notice.)
The position of this object is very important for searching the target.
When this position is too low, the searching Ray will be obstructed by its turret or its gun barrel.


(Tips)
When this position is set to so high, the AI will get a full view of the scene as seen from a reconnaissance plane.
In the sample tank "Karl_AI", this height is set to 100 meter from the ground.



*** AI_Hand ***

This object must be placed under "AI_Core" in the hierarchy.
You can see this object as a translucent box in front of AI tank.


"AI_Hand" detects an obstacle in front of the tank by using a BoxCollider as a trigger.
(Notice.)
"AI_Hand" cannot detect an object without Rigidbody.
When you want to place a barricade on the NavMesh, attach a Kinematic Rigidbody into it.

AI tries to escape from the stuck by instantiating the "Obstacle_Prefab", or by changing the next waypoint.