Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Tactical Shooter AI - Asset Store Pack

Discussion in 'Works In Progress' started by squared55, Mar 2, 2015.

  1. GWStudio

    GWStudio

    Joined:
    Sep 27, 2016
    Posts:
    64
    i did it but the agent get back to patroll before arive to sound location.. how to make it investigates or wonder arround the sound position then if he didn't find the player get back to patrolling .. one more issues how to make the grenade damage my RFPS player ..
    Thanks for answering. .
     
  2. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Default behavior of the investigate sound function is to do just that- go close to the location of the sound and then return to the idle behaviour. I can look into making you a version of the investigate sound function that has the agent wait around a bit after reaching the sound source. (However, as stated above, I'm pretty busy at the moment, so this might take me a while to get around to.)


    As for making AI grenades damage the RFPS player- in short, open the TSAI explosion script and uncomment the RFPS lines in the middle. Then set the layermask appropriately so it doesn't interpret the RFPS player itself as a wall and do no damage. More detail can be found in the RFPS integration instructions included with the package.
     
  3. khaven

    khaven

    Joined:
    May 24, 2017
    Posts:
    2
    Hi squared55, is there any way i can use object pooling with ai gameObeject? I'm trying to use this on mobile platform.
     
  4. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    People other than me have done it, but it did require some code modification. IIRC, someone actually made a video demonstrating how to integrate TSAI with an asset called Pool Boss, but on taking a brief look, I can't seem to find the video again.
     
  5. Virtuactions

    Virtuactions

    Joined:
    Jun 5, 2017
    Posts:
    12
    Hi, bots on my map are pretty stupid and i don't understand why.
    http://take.ms/WIaZt
    I start 10x10 battle, there is still plenty of blue soldiers, but all red soldiers stand near one of them and do nothig. This blue soldier is shooting randomly. And this is not the only strange thing. Often bots don't see each other in 1 meter distance. They can stand on one place for 2-3 minutes before start moving, or don't move at all. They move in group without reacting to enemy bots. Bots in one team can intentionaly shoot each other. And bots like to shoot to nowhere.
    And on demo map everything works ok. What can it be?
    I am using same bot prefab like on demo map, only change their team parameters at runtime on awake (team, allied teams, enemy teams).
     
  6. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Have you configured the AI Controller to match the demo scene? You should also use the "SetNewTeam(int newTeam)" method to change teams if you are not already.
     
  7. GWStudio

    GWStudio

    Joined:
    Sep 27, 2016
    Posts:
    64
    I hope u make the version of the investigate sound function that make the ai to investigate around the sound location??!!
     
  8. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Sorry for the late response. Like I said, I was extremely busy.

    Anyways, here is a version of the Investigate Sound behavior that will cause the agent to wait for a certain amount of seconds before returning to their regular idle behavior.

    Replace the InvestigateSound class in the CustomAIBehaviour with this one.

    Code (CSharp):
    1. namespace TacticalAI
    2. {
    3.     public class InvestigateSound : TacticalAI.CustomAIBehaviour
    4.     {
    5.  
    6.         float radiusToCallOffSearch;
    7.         //Change this to change the amount of time the AI waits!
    8.         float timeUntilReturnToIdle = 10.0f;
    9.  
    10.         public virtual void Inititae()
    11.         {
    12.             base.Initiate();
    13.             radiusToCallOffSearch = baseScript.radiusToCallOffSearch;
    14.         }
    15.  
    16.         public override void AICycle()
    17.         {
    18.             //End the behaviour if we get close enough to the source, or we engage a target.
    19.             if(navI.GetRemainingDistance() < radiusToCallOffSearch)
    20.             {
    21.                 timeUntilReturnToIdle -= Time.deltaTime;
    22.             }
    23.  
    24.             if (timeUntilReturnToIdle <= 0 || baseScript.IsEnaging())
    25.             {
    26.                 KillBehaviour();
    27.             }
    28.             else
    29.             {
    30.                 targetVector = baseScript.lastHeardNoisePos;
    31.             }
    32.         }
    33.  
    34.         public override void OnEndBehaviour()
    35.         {
    36.             Destroy(this);
    37.         }
    38.     }
    39. }
    Let me know if it works.
     
    julianr likes this.
  9. Virtuactions

    Virtuactions

    Joined:
    Jun 5, 2017
    Posts:
    12
    How can I get bot who is owner of bullet, that hit me? Is there any built in method or i need to modify plugin code to achieve that?
     
  10. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Unfortunately, there is no built-in way to tell which bullet was fired by what agent. You may want to attack a new script to the bullet prefab instead of modifying the TSAI code, though.
     
  11. Virtuactions

    Virtuactions

    Joined:
    Jun 5, 2017
    Posts:
    12
    So I need to create a bullet prefab for every bot and assign this prefab to gunscript at runtime?
     
  12. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    That's one way to do it. But, upon thinking about it more, the best way would require only a bit of modification to the code.

    First, you'd make a script which holds the ID of the agent which fired the bullet and transfers the data to the target (or you could integrate it into the existing bullet script, if you'd find that easier).

    Then in the GunScript you would access this new script/code when the bullet is instantiated and provide the information that way. You can look to how I set the target of homing rounds for an example.
     
  13. capitalJmedia

    capitalJmedia

    Joined:
    Feb 10, 2011
    Posts:
    368
    Great job on the plugin!

    What is the best way to give a new destination to the ai agent. For example, a new base or flag to defend during the game? I tried setting the key transform of the BaseScript to the new target transform and setting the idle behaviour to "moveToTransform" but I think this only seems to work when the agent is first instantiated not during gameplay.
     
  14. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    "Berserker" is the combat behavior which moves the enemy to a specific point. By default, this point is the target, hence the name, but you can override the destination via the key transform.
     
  15. capitalJmedia

    capitalJmedia

    Joined:
    Feb 10, 2011
    Posts:
    368
    Ok great thank you.

    Will using berserker behavior let the agents still engage enemies along their path? one thing I noticed with the move to transform behaviour was that they would often run right past enemies in a blind rush to the destination, which looks a bit funny that they ignore an enemy a few feet away.
     
  16. capitalJmedia

    capitalJmedia

    Joined:
    Feb 10, 2011
    Posts:
    368
    As a general suggestion for coding that might make the plugin a bit more extensible, would be to provide more virtual functions that can be overridden to allow for easier customization without having to edit your original code.

    Also things like the spawner have a reliance on a hardcoded sendMessage that will only work with the spawnerscript class as it is written. This is when a new unit is spawned and then it looks like the spawner registers itself with the new unit so that when the unit is killed the spawner will be notified, but as it takes the spawner itself as a parameter, it will only ever work with that specific spawner class. Would be cool if this was a bit more generic and instead of passing in the spawner as the parameter, we just passed in the gameobject so that the agent could send out the killed message to any script on the spawner object rather than only this one class.

    Anyways, just some general thoughts, but overall it's fantastic!
     
  17. capitalJmedia

    capitalJmedia

    Joined:
    Feb 10, 2011
    Posts:
    368
    I tried the berserker style but they pretty much just run at the set destination without stopping for cover as much. I prefer the feel of the Tactical behaviour but is there a way to just give them a general point to move towards and make sure they do so carefully so they stop at cover, don't just run into enemy fire, etc..?
     
  18. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    You might want to try using the Advance Towards Target cover finding method along with Tactical. This will make them choose cover nodes that are progressively closer to the Key Transform.
     
  19. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,062
    Trying to get this working with Invectors TPC. So far so good, however when I apply the Target script on the Player, the AI do not see me, yet when I apply this script to the camera they do, but shooting at the camera which is behind the player. Any ideas?
     
  20. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Sounds like a layermask issue is causing the agent to view the player as a wall they can't see through. Try excluding the player's layer from the AI Controller's layermask.
     
    julianr likes this.
  21. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,062
    Thanks. I'll give it a go and let you know if it works.
     
  22. capitalJmedia

    capitalJmedia

    Joined:
    Feb 10, 2011
    Posts:
    368
    Thanks. I tried changing the cover seek method to Advance towards target, but doesn't seem to change anything. They still don't move towards the key transform. Maybe you can give me some instructions based on this desired behaviour:

    1. I set a transform or position of an capture point for the agent i want them to proceed to
    2. They move towards that point, using cover if they are in combat, otherwise just walk towards it if not in combat
    3. Once the point is captured, I give them another point to move towards (repeat step 2)

    Any thoughts on how to accomplish that?
     
  23. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    580
    Hi,
    I'm looking for a good AI solution. Is it possible to create AI bots as enemies for my player?
     
  24. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Are using manually placed cover nodes?

    You can use TSAI to make enemy NPCs, however, depending on what movement/other mechanics you player has, the TSAI agents may not be able to do everything your player can.
     
  25. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    580
    Thank you.
     
  26. capitalJmedia

    capitalJmedia

    Joined:
    Feb 10, 2011
    Posts:
    368
    Yes, I put short and tall cover node prefabs into the scene along the path the agents take to get to a control point. I put the nodes as children of other objects (props, cars, etc..), not sure if that matters or whether the cover nodes need to be in the root of the scene.
     
  27. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    There's an error in the CoverFinderScript. Line 123 should read

    Code (CSharp):
    1. return FindAdvancingCover(targetTransformPos, transformToDefend);
     
  28. Kiwi2112

    Kiwi2112

    Joined:
    Jun 30, 2017
    Posts:
    7
    How do you get the AI to hear gunshots, they only detect me through vision (iv'e played around with the shout options.)

    Im also using UFPS.
     
  29. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    There should be a script included with the package that makes a "sound" the AI can hear when the prefab on which the script is placed is instantiated. So, putting it on your bullet prefabs should do the trick.
     
  30. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    21
    Hi,

    How would I go about disabling an agent's ability from engaging with other (enemy) agents until the player tells them to?

    In the game I am working on the player can command agents to follow and assist them and I would like to stop agents from engaging with enemies until the player commands them to.

    Thank you.
     
  31. Kiwi2112

    Kiwi2112

    Joined:
    Jun 30, 2017
    Posts:
    7
    Quick question, can this work with invector? I can hurt enemies but they just stand there, I have the teams all properly set in the target script.
     
  32. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Try setting the priority (on their TargetScript) for the enemies that you do not want the agents to engage to a value less than 0. Then when you want the agents to attack them, restore their priority to a value greater than 0.

    You could also change the priorities of the agents to different amounts based on player commands in order to get your friendly agents to focus fire (or do the opposite- give friendly agents a higer priority than the player to make distractions more effective).

    I don't offer official Invector support, but if you have the damage systems working together, that's 99% of the challenge.

    Have you made sure that the player's physics layer is not included in the AI Controller's layermask? If the player's target script object is hidden behind the player's collider, the agents might not be able to see it.
     
    Last edited: Jul 11, 2018
  33. musolo

    musolo

    Joined:
    Sep 12, 2014
    Posts:
    209
    hi. I have two identical agents with same settings but one of them shoots at the other the same moment he sees him, which is good. Other one is practically identical to the first one but he does not shoot right away but startwalking to first agent and shoots only when he is at nearmele distance.
    What could that be?
    Help please!!!
     
  34. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Probably some discrepancy between the settings of the two agents. Do you have sprinting enabled on the agent that is not working? Are they both using the same combat behavior?
     
    Last edited: Jul 14, 2018
  35. PicturesInDark

    PicturesInDark

    Joined:
    Jun 13, 2013
    Posts:
    73
  36. ricogs400

    ricogs400

    Joined:
    Aug 4, 2017
    Posts:
    13
    This might be way late, but lookup Core Game Kit, it uses pooling and spawners and has tutorials on setting it up with TactAI.
     
  37. ricogs400

    ricogs400

    Joined:
    Aug 4, 2017
    Posts:
    13
    squared55,
    Are these variables 'timeBeforeTargetExpiration' or 'willEverLoseAwareness' in TargetScript still used? The one is a public var to be set, but it looks like the code that would use them is commented out. I'm setting up difficulty levels and I'd like to use them as some of my variables. Are they not used in the latest release?
    Thanks, and by the way this is a great AI system.

    public int timeBeforeTargetExpiration = 15;

    Here's the commented out sections where they appear in TargetScript:

    //Old target loss method
    /*IEnumerator CountDownToTargetExperation()
    ...
    yield return new WaitForSeconds(timeBeforeTargetExpiration);
    }
    }*/

    //public bool willEverLoseAwareness = false;
     
  38. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Yes, I changed the way target loss works a while back.
     
  39. ricogs400

    ricogs400

    Joined:
    Aug 4, 2017
    Posts:
    13
    OK, thanks. Do either of these parts of the TargetScript below make AI aware of enemies they haven't seen yet?
    In my game, I only want AI to engage if they have spotted an enemy, have been notified by a shout from another AI or a sound.
    If this does do make them aware of unseen enemies and if these parts are only to keep the action going in a deathmatch type scenario, can they be removed?

    *************************************
    //Settle for targets we can't see, if we have to.
    else if (!foundTargetWithLoS)
    {
    enemyScoreCheckingNow = Vector3.SqrMagnitude(enemyTransformCheckingNow.position - targetObjectTransform.position);
    if (enemyScoreCheckingNow < currentEnemyScore || currentEnemyScore < 0 || !foundTargetWithLoS)
    {
    currentEnemyTarget = listOfCurrentlyNoticedTargets;
    currentEnemyScore = enemyScoreCheckingNow;
    }
    *************************************
    //If all of the above fails, pick a random target- even if it's one we haven't seen
    if (currentEnemyTarget == null && enemyTargets.Length > 0)
    {
    currentEnemyTarget = enemyTargets[Random.Range(0, enemyTargets.Length - 1)];
    }
    *************************************
     
  40. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    That is so that idle behaviours like Search work as intended. If you use something like Patrol, then it can be safely ignored, as those behaviors are not tied to the currently selected target.
     
  41. ricogs400

    ricogs400

    Joined:
    Aug 4, 2017
    Posts:
    13
    Great, that should help with my tweaking the other values on the behaviors. I use Wander, Patrol and Search, so I will leave it as is because it seems to be performing well, I just wanted to make sure there wasn't something happening that might make all the AI types look like they know where the player is without having seen them.
    Thanks.
     
  42. Meena_Fari

    Meena_Fari

    Joined:
    Mar 27, 2016
    Posts:
    12
    Hi, @squared55 very first very great pack, love it,
    I want to know, how can I set distance, keeping enemy his distance from player, and fire from some distance.
    and must take cover after some time.
     
  43. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    The variables defining the desired combat/cover range and the minimum desired distance to the player when out of cover can be found in the Base Script and Cover Script.

    Choose "Tactical" for the agents combat behaviour if you want them to take cover.
     
  44. Meena_Fari

    Meena_Fari

    Joined:
    Mar 27, 2016
    Posts:
    12
    Thanks for reply, but I am having issue, When I select mode to Tactical, agent simply goes to player, and shooting, not taking any cover, just firing and going to player position. but I want agent, firing some time towards player then should take cover at different position,then fire and after fire change position, and fire, again and again , until unless it dies. Even my cover positions are well set, in scene, according to your demo scene, I am uploading image of my base script and cover, kindly guide me. for my scenario (bold text). tac.JPG
     
    musolo likes this.
  45. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Have you set the layer masks on the AI Controller/Cover nodes to include the objects that make up your level? If you haven't the AI will be unable to find valid cover as it doesn't know which objects are solid.

    Similarly, make sure that your player's physics layer is NOT included.
     
    Last edited: Aug 8, 2018
  46. Meena_Fari

    Meena_Fari

    Joined:
    Mar 27, 2016
    Posts:
    12
    still, issue remain as you can see in image,, enemies are at player position, and don't know why, .. have you any tutorial about setting tactical and cover behavior 369.JPG
     
    Last edited: Aug 9, 2018
  47. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Can you tell me what the layer mask variable is on your AI controller and on your cover nodes? I have attached a picture for reference.

    lm.png

    lm2.png

    Please let me know which layers you have selected and what layers your player and level parts are on.

    Additionally, make sure your cover nodes are placed close behind cover objects. Agents will only take cover at locations where the player does not have a clear sight line to the location of the solid sphere, but does have a clear line of sight to the location of the wire sphere.
     
    Last edited: Aug 10, 2018
  48. Meena_Fari

    Meena_Fari

    Joined:
    Mar 27, 2016
    Posts:
    12
    My player has layer of NPC, and controller, cover node have layer mask of Cover, and environment is of layer mask.
    attaching images, have a look.
    and I made very huge blockers (blocker contain box collider and have default layer) for cover that for not clear sight, But still enemy didn't take cover and come to player.. base script is set to MY AI type is Tactical, and My idle behavior set to search
    cover PLyer_script.JPG
    blocker.JPG
    player_layer.JPG cover_node_script.JPG controller_layer.JPG
     
    Last edited: Aug 13, 2018
  49. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    738
    Ive just come back to this awesome asset. But now my guys run so close to me they force themselves under me and im on their head, I cannot find how to stop them coming so close? Is there a variable for this ?
     
  50. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,814
    Hmm.

    Just to make sure, is the physics layer of that big wooden box set to "Cover"? Additionally, what happens if you enable "should use dynamic cover" in the Cover Finder Script? Is "Performance Mode" disabled on the AI Controller? Sometimes that setting can cause problems.

    There is a min dist to target when out of cover variable in the base script. Also, make sure your player is not included in the various TSAI layermask variables. Finally, attach a navmesh obstacle to your player to stop them from running underneath you.
     
    radiantboy likes this.