Search Unity

Tactical Shooter AI - Asset Store Pack

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

  1. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Also I have a prob;lem where the AI justs stop shooting sometimes ;-/
     
  2. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Thanks man! And any idea why he runs up to me and stands there but doesnt shoot sometimes. Oh and often he wanders right past me, man this AI stuff is FAR too hard :(
     
  3. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    I can't remember if I already gave this advice to you, so apologies if I'm being redundant, but did you set the various layermasks to not include the player's physics layer?

    Also, make sure your gun settings allow the agent to fire frequently enough.

    Finally, try increasing your agent's field of view.
     
  4. musolo

    musolo

    Joined:
    Sep 12, 2014
    Posts:
    238
    Hi squared55!
    Remember i was talking about tanks with your AI? tank hull was off it`s AI movement direction and it seemed as if it was sliding on surface like hovercraft.
    I disabled animation script and now it tank hull follows it`s agent direction exactly so it loocks like actual tank movement now!!!
    One thing is tah it agent turns in place pretty damn fast with animation script disabled. Is there a way for me to control turn speed of agent with animation script disabled?
    Thanks!
     
  5. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    I don't have Unity up right now, but if you go to the Navmesh Agent, I think you can adjust the turning speed (referred to as angular velocity, if my memory is correct).
     
  6. musolo

    musolo

    Joined:
    Sep 12, 2014
    Posts:
    238
    Thanks!!!
     
  7. musolo

    musolo

    Joined:
    Sep 12, 2014
    Posts:
    238
    squared55
    Could you make spawner be able to spawn set of agents when player or opposite team bot enters a sertain trigger?
    And how would you suggest to make agents to spawn at different points on the map each time mission begins?
     
  8. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    I'd recommend writing a script that stores various empty game objects that mark potential spawn positions in an array and then instantiating agents at the position of a random object in said array.

    There should be a simple wave spawner script in more recent versions of the package that uses a similar technique to help you get started.
     
  9. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    260
    Hi,

    I have an issue related to the Rotate to Aim Gun Script and my agent's firing animation. The firing animation that I am using has a large amount of recoil. This recoil makes the bullet spawn object point into the air, which causes the Rotate to Aim Gun Script to rotate the agent's spine bone downward. This makes the agent hunch over every time a shot is fired. How should I approach modifying the Rotate to Aim Gun Script to fix this?

    Also, I have a series of animations that depict the agent aiming at different angles and orientations. What would be the best way to modify the Rotate to Aim Gun Script to allow for partial aiming control by an animation blend tree?

    Thanks.
     
  10. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Hi,

    Sorry for the late response. :)

    My first thought for dealing with the recoil would be to have the GunScript call a method in the RTAG script which would temporarily suspend the movement. The issue with this is that without the RTAG script, the animation would fade back to center, so if the agent is aiming anywhere but straight ahead, things would look weird.

    One solution could be to hook the RTAG script up with an object which is in the same position as the gun when idle, but does not follow it when it recoils (maybe by parenting it to the chest bone?) Thus, the gun could move freely while the RTAG aims forward.

    Your second issue would require a near complete rewrite. You'd probably want to determine the angle in each direction (x/y) that the agent would have to aim and then compare that to the maximum rotation of your animations. You'd then interpolate to the correct frame in the animation using the above ratio and play it accordingly. (I am assuming you have two animations, horizontal and vertical here.)

    Additionally, if you do use an animation-driven aiming system, then you could just layer your firing animation on top of the rotation whenever the agent shoots, solving your first problem.
     
    Last edited: Sep 2, 2018
  11. musolo

    musolo

    Joined:
    Sep 12, 2014
    Posts:
    238
    Hi squared55!
    What would it cost for you to make advanced spawner for your product?
     
  12. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Well, I'm not really doing commissions at the moment. With that said...

    Code (CSharp):
    1.     public Transform player;
    2.     public float distance;
    3.     public GameObject objectToActivate;
    4.  
    5.     void Update()
    6.     {
    7.         if(Vector3.Distance(transform.position, player.position) < distance)
    8.         {
    9.             objectToActivate.SetActive(true);
    10.         }
    11.     }
    That bit of code should allow you to activate any game object when the player gets within a set distance of the object that the above code is attached to- such as a spawner that starts the game disabled.

    Just make sure you don't attach the above code to the spawner itself because it won't work when disabled either.

    So, yeah. With this plus the included spawner script, you should be able to spawn waves of agents whenever the player gets close enough to a specific point.
     
    Last edited: Sep 4, 2018
  13. musolo

    musolo

    Joined:
    Sep 12, 2014
    Posts:
    238
    Thanks!
    If one spawner for all traditional scenarios sounds tedious, maybe few smaller ones that will fit their specific cases?
    Your product needs them badly.
     
  14. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    I honestly can't really think of many scenarios that can't be covered by what's already there. You have waves, you have random spawn points, you have proximity activation that works with any game object. If what you want is for waves of enemies to spawn when the player gets to a certain area, that should about cover it.

    Maybe you have another request that can be covered by a short script like the one above (if so, feel free to ask! :) ), but if you need something more complex than that, then we've moved well beyond the scope of this AI asset.
     
    Last edited: Sep 6, 2018
  15. Grandart

    Grandart

    Joined:
    Aug 9, 2018
    Posts:
    2
    please I need the script VP_FX Bullet can you right for me
     
  16. Grandart

    Grandart

    Joined:
    Aug 9, 2018
    Posts:
    2
  17. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Hello,

    Unfortunately. there is no script entitled "vp_FX Bullet" in Tactical Shooter AI. That sounds like a UFPS script, and you should ask the developer of that asset for assistance in this regard.
     
    Last edited: Sep 10, 2018
  18. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    Hi,

    I have an issue with enemy agents I have (custom characters) where I have a rather weird issue.

    I have some that are using settings for "Tactical/Wander" that being what I need for some agents as opposed to say Skirmish/Wander.

    I want them to use cover. I have a test level where I set them up and they work just fine and I have two in a real game level where they also behave as they should do - where they will take cover almost anywhere they choose, crouch and shoot and so on as they should. All very good :)

    My problem is that in a SciFi level I have where I want to use the SciFi characters and in that level the very same characters which work in the previously mentioned levels don't work. (As a matter of fact the default TSAI characters don't work either) and all when "Tactical" is chosen as opposed to Skirmish which all work OK in the SciFi level if that is chosen :)

    When using "Tactical" on the characters in the SciFi level as soon as they alert and see they player/shoot at the player the freeze in position and shoot only when the player is in range but do nothing else except stand on the spot and wont move, they wont follow/move to player, wont crouch or take cover or dodge or anything but shoot/throw grenade from a frozen spot location? No matter what the player does or where he is in relation to them, near or far they just remain stuck to the spot forever.

    Been at it about a week long and endless hours per day but cant solve this one. It makes little sense as I don't see any difference in the levels where they work and the SciFi level where they wont despite the characters being the same in each too. I use the same prefab characters. Effectively in all levels they are upon a terrain and as far as I am aware all is equal in all levels but for some reason TSAI apparently does not think so :)

    I have attached two screen shots :

    1. Military level where all TSAI agents including my Scifi ones using "Tactical" work perfectly.

    2. SciFi Level where two of the same characters are placed using "Tactical" where they don't and freeze to the spot.

    I have one non critical error message in the console which is below :

    TSAI Cover Error when using Tactical behaviour. (I am not using CombatRange as a setting as it refers too, but in any case no setting make any difference)

    NullReferenceException: Object reference not set to an instance of an object
    TacticalAI.CoverFinderScript.FindCoverWithinCombatRange (Vector3 targetTransformPos, UnityEngine.Transform transformToDefend) (at Assets/Tactical Shooter AI/Tactical AI/Csharp/AI Behaviour Scripts/CoverFinderScript.cs:151)
    TacticalAI.CoverFinderScript.FindStaticCover (UnityEngine.Transform targetTransform, UnityEngine.Transform transformToDefend) (at Assets/Tactical Shooter AI/Tactical AI/Csharp/AI Behaviour Scripts/CoverFinderScript.cs:118)
    TacticalAI.CoverFinderScript.FindCover (UnityEngine.Transform targetTransform, UnityEngine.Transform transformToDefend) (at Assets/Tactical Shooter AI/Tactical AI/Csharp/AI Behaviour Scripts/CoverFinderScript.cs:105)
    TacticalAI.Cover.AICycle () (at Assets/Tactical Shooter AI/Tactical AI/Csharp/AI Behaviour Scripts/CustomAIBehaviour.cs:584)
    TacticalAI.BaseScript+<AICycle>c__Iterator1.MoveNext () (at Assets/Tactical Shooter AI/Tactical AI/Csharp/AI Behaviour Scripts/BaseScript.cs:246)
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

    Any help is appreciated.
    TheBarracks-0.png In the shot above AI works fine
    Game-0.png
    In the shot above AI is stuck to the spot permanently.

    Thank you very much.
     
  19. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Hello,

    My first guess is that your sci-fi scene doesn't have an AI Controller in it and as a result cannot find any cover points. Create an empty game object in the scene and place the Controller script on it, and assign the layermask variable in the script accordingly (so that the agents can't see through walls).

    Hopefully this works. If not let me know and we can explore further options. Any additional details you can provide regarding your scene set-up would also be useful.
     
  20. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    Hi squared55,

    I have tried replacing and resetting the Controller anew and even copied one from another level and also saved from a working level as a prefab and used same controller in the SciFi level. Stuck with this much like my AI is in one place :)

    What is happening is that the AI will approach the player normally attacking the player until the AI gets within a range which he seems to be fixed upon - thereafter the AI will stick in that exact position and never move again in any direction no matter what the player does or wherever the player moves to at any distance or location in the level though the AI will continue to attack the player at a range he decides to continue to do from his frozen position.

    As I have tried hundreds of permutations its a job to know what exactly is making this happen, however the constant is whatever settings I use once he stops moving that's it - he wont respond to TSAI behaviours of movement further at all - ever.

    As said same AI, same settings work fine in other levels and I have run out of logical thought about why this is happening - nothing special or different in the level or level set up I am aware of. It is illogical to me so that's a big prob as without any kind of logic I cant work it out.

    Why would I not be able to force the AI to move and follow the player once he gets within a certain range, something must be preventing the AI at that stage? That is notwithstanding why he wont use cover - he wont even move once he stops doing so? There must be some setting preventing the AI movement but why just in one level and not others?

    The AI is on Terrain its set to untagged and default - same as all other levels - the Unity default (I am using RFPSP) works fine.

    I have attached another screen shot you can see the AI is at a range and that's about the range he stops/stays every time and I cant affect that apparently.

    I don't really know where else to look after six long days and don't particularly fancy another 20 hour day knocking my head against an immovable object (excuse the pun) again today seemingly just repeating the same things over and over again expecting a different result. The definition of madness so they say :)

    Looks like I am stuck with with no cover behaviour in this level unless I can unlock the issue - could be some corruption is about all I am left with thinking but I don't buy that :)

    Anyway thanks if you can suggest anything else as I have run out of logical thoughts or ideas and just doing anything blindly now in a effort of desperation.

    Thanks very much.

    Peter
     

    Attached Files:

    • h2-1.png
      h2-1.png
      File size:
      699.3 KB
      Views:
      776
  21. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Oh, this just reminded me that there was a user a while back with the exact same issue. If I remember correctly, the solution was to

    A) Place a cover node prefab anywhere on the navmesh.

    B) Ensure that the timescale is not 0 in the project settings.

    Alternatively, maybe you could just put your entire sci-fi level into a prefab and then drop it into a duplicate of a scene that works?
     
    Last edited: Sep 11, 2018
  22. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    Hi squared55,

    Thanks for that.

    Sorted my issue I believe other than I will just have to reset my AI settings as per needed for each level/scenario as \i had messed them up trying to find out what the prob was....

    Anyway I tried the custom AI Character in another SCiFi Level and it worked fine using any tactical settings...

    I new there was an issue just in the level shown above. If you look at the screen shot in the previous post - the problem seems to have been that in the SciFi Buildings in the distance - build from prefabs I made using "ProBuilder" some of the prefab Parts were the issue. I isolated them by deactivating everything when the AI worked and then turning things back on until I found out what prefab objects were causing and issue - and why was because the prefab parts had been duplicated and I had not in a few instances hit the "Apply" button on the duplicates. That alone offended Tactical AI :) and me too!

    Almost a weeks work lost but don't know why I did not do that before now.

    Hopefully I am now away to go :)

    Thanks again for your help which is appreciated. One more thing sorted Yeah.

    I have three custom characaters converted to TSAI and a lot more to do and a lot more level building to do so plenty to get on with.

    Peter
     
  23. HorusVision

    HorusVision

    Joined:
    Jun 7, 2018
    Posts:
    4
    While my bots are wandering, I want them to reach their waypoint, then stop walking for a few seconds, then resume walking. Should I create a new AIBehavior for waiting, and have the bots cycle in/out of that behavior? Or should I simply modify the Wander class by adding a timer into it?
     
  24. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Huh. I never would have suspected that Probuilder was the culprit. Thanks for letting me know the issue was resolved!

    Either way would work, although adding the timer to the original behavior would be a bit faster. If you ever want to go back to the original no-wait behavior, you could just set the timer to 0.
     
  25. musolo

    musolo

    Joined:
    Sep 12, 2014
    Posts:
    238
    Hi!
    I had issue with performance on mobile due to amount of bullets in the scene and we had this discussed this once on page 30.
    I asked:

    Can they shoot each other with raycast "bullets" and not just projectile? So machine gunners and riflemen would use raycast and not cluttered scene with bullet prefabs causing drammatic batches increase and killing framerate on mobile.
    And projectile type bullets would be used only by snipers.
    Could you help me out o this one?
    Thanks!
    Your answer was:
    Under the current system, just make the bullets really, really fast so that they appear and disappear within a single frame. No raycasts with no bullet object at the moment, however.

    Is it implemented yet or maybe there is other solution to this issue? You said to make bullet to live shorter live. But it needs to live long enough to reach it`s target half a mile away. So i get like 100 phisical projectiles. And it cripples framerate awfully.
     
  26. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    With regards to the time to live issue, if you set the speed to something ridiculously high, like 10000000000, then the bullet would only need to exist for a tiny fraction of a second as it would cross the entire game world in a single frame- effectively instantly.

    You could also decrease the rate of fire on the bullets, and maintain the illusion of a higher rate of fire by using a sound effect with a gunshot noise looped several times. To the player it would seem as though the gun is firing at a higher rate than it actually is, just that only every few rounds is a visible tracer. Of course, this would require you to have such a sound effect.

    Projectiles are still the only officially supported system. If you have your own hitscan code that you want to use (say, you have a player with a hitscan gun), then maybe you could replace the GunScript's bullet instantiation with that code. IF I have time in the next week, I might whip up a rudimentary version of this that could help you get started. No promises, though. :)
     
    Last edited: Sep 16, 2018
  27. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    Another question if anyone can help please?

    I have custom enemies with weapons set up and when they fire their weapon for some reason the fire (Bullet Spawn) sound "Gunshot" does not play - at least I do not hear it even though I have tried various things including making sure the sound range would be large enough to do so.

    For the life of me I cant understand why this might be as it should be fairly simple to get it to work following the default AI Characters set ups and settings which is what I do.The sound is indicated in the AI's bullet spawn appropriate parameter field as with the default AI's.

    Thanks for any help.

    UPDATE : Fixed this now thanks so you can ignore the post (hopefully) :)

    regards

    Peter
     
    Last edited: Sep 20, 2018
  28. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    If you don't mind me asking, what ended up being the problem?

    OK, so here's the rudimentary modifications I mentioned in the last post.

    Add these variables with all the others at the top:

    Code (CSharp):
    1.  
    2. float damage;
    3. LayerMask raycastLayerMask;
    4. bool useRaycast = false;
    ADD this code in Awake (to gather information from the bullet prefab. If the bullet prefab's speed is greater than 5000, a raycast will be used)

    Code (CSharp):
    1.      
    2. GameObject bullet = (GameObject)(Instantiate(bulletObject, bulletSpawn.position, fireRotation));
    3. if (bullet.GetComponent<BulletScript>().speed > 5000)
    4.             {
    5.                 damage = bullet.GetComponent<BulletScript>().damage;
    6.                 raycastLayerMask = bullet.GetComponent<BulletScript>().layerMask;
    7.                 useRaycast = true;
    8.             }
    9.             GameObject.Destroy(bullet);
    REPLACE this section in the gun script (around line 344):

    Code (CSharp):
    1. GameObject bullet = (GameObject)(Instantiate(bulletObject, bulletSpawn.position, fireRotation));
    2.                             //If this is using the TacticalAI Bullet Script and is a rocket launcher
    3.                             if (isRocketLauncher && bullet.GetComponent<TacticalAI.BulletScript>())
    4.                             {
    5.                                 bullet.GetComponent<TacticalAI.BulletScript>().SetAsHoming(targetTransform);
    6.                             }
    With
    Code (CSharp):
    1.  
    2. if (!useRaycast)
    3. {
    4.      GameObject bullet = (GameObject)(Instantiate(bulletObject, bulletSpawn.position, fireRotation));
    5.      //If this is using the TacticalAI Bullet Script and is a rocket launcher
    6.      if (isRocketLauncher && bullet.GetComponent<TacticalAI.BulletScript>())
    7.      {
    8.           bullet.GetComponent<TacticalAI.BulletScript>().SetAsHoming(targetTransform);
    9.      }
    10. }
    11. else
    12. {
    13.      RaycastHit hit;
    14.      if (Physics.Raycast(bulletSpawn.position, bulletSpawn.forward, out hit, 5000, raycastLayerMask))
    15.      {
    16.      //Damage processing code goes here
    17.      //For example:
    18.      hit.collider.SendMessage("Damage", damage, SendMessageOptions.DontRequireReceiver);
    19.      }
    20. }
    21.  
    Note that this specific instance only applies the most basic of damage methods. You can look at all the stuff that TSAI can do when a bullet hits its target in the ApplyDamage() function in the BulletScript, but as that alone is about 30 lines long, I omitted it for the sake of brevity.

    If you do want to add all those functions in, you'll need to create variables where necessary (for example, a string "hitEffectTag" and a GameObject "hitEffect"), and (optionally) extract the values from the bullet in awake for ease of use ("variableName = bullet.GetComponent<BulletScript>().variableName;").

    Also, you will need to get rid of the "yield return null" no matter what as FireOneShot() in the bulletscript is not an IEnumerator. Hopefully this helps you get started!
     
    Last edited: Sep 21, 2018
  29. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    You could try a 3rd party spawning solution like Core GameKit. I use that and it allows you to do some complex spawning scenarios.
     
  30. pierre92nicot

    pierre92nicot

    Joined:
    Aug 21, 2018
    Posts:
    57
    Hi,
    Unity noobs here.
    I am struggling to make my projectile script hurt the agent.
    The script look like this :


    Code (CSharp):
    1. [SerializeField] protected float baseDamage = 100;
    2.     [SerializeField] protected float maxDistance = 100;
    3.     [SerializeField] protected AnimationCurve damageOverDistance;
    4.  
    5.     [SerializeField] [ReadOnly] protected float distanceTraveled;
    6.     protected Vector3 initialPosition;
    7.     protected Vector2 previousPosition;
    8.  
    9.  
    10.     [System.Serializable]
    11.     public struct BulletImpactEffect
    12.     {
    13.         public string hitObjectTag;
    14.         public GameObject impactParticle;
    15.         public AudioClip[] impactAudio;
    16.         public GameObject exitParticle;
    17.         public AudioClip[] exitAudio;
    18.         public float scale;
    19.     }
    20.  
    21.     [SerializeField] protected List<BulletImpactEffect> impactEffects;
    22.  
    23.     void Start()
    24.     {
    25.         Screen.fullScreen = true;
    26.         rb.AddForce(transform.forward * muzzleVelocity, ForceMode.Impulse);
    27.         previousPosition = transform.position;
    28.         Destroy(gameObject, 7.5f);
    29.     }
    30.  
    31.     void Update()
    32.     {
    33.         float distance = Vector3.Distance(transform.position, previousPosition);
    34.  
    35.         distanceTraveled += distance * Time.deltaTime;
    36.  
    37.         previousPosition = transform.position;
    38.     }
    39.  
    40.     void OnCollisionEnter(Collision col)
    41.     {
    42.         Effect(col, true);
    43.         Destroy(gameObject, 0.02f);
    44.     }
    45.  
    46.     void Effect(Collision col, bool ENTEREXIT)
    47.     {
    48.         for (int i = 0; i < impactEffects.Count; i++)
    49.         {
    50.             BulletImpactEffect impactEffect = impactEffects[i];
    51.  
    52.             if (col.gameObject.tag == impactEffect.hitObjectTag || col.gameObject.HasTag(impactEffect.hitObjectTag))
    53.             {
    54.                 GameObject clone = null;
    55.                 GameObject particleEffect = ENTEREXIT ? impactEffect.impactParticle : impactEffect.exitParticle;
    56.                 //AudioClip audioEffect = ENTEREXIT ? impactEffect.impactAudio[Random.Range(0, impactEffect.impactAudio.Length - 1)] : impactEffect.exitAudio[Random.Range(0, impactEffect.exitAudio.Length - 1)];
    57.  
    58.                 if (particleEffect)
    59.                 {
    60.                     clone = Instantiate(particleEffect,
    61.                         col.contacts[0].point + col.contacts[0].normal * 0.01f,
    62.                         Quaternion.FromToRotation(Vector3.forward, col.contacts[0].normal)) as GameObject;
    63.  
    64.                     Destroy(clone, 3f);
    65.  
    66.                     Transform decal = clone.transform.GetChild(0);
    67.  
    68.                     if (decal)
    69.                         if (decal.name == "Decal")
    70.                         {
    71.                             decal.SetParent(col.transform, true);
    72.                             Destroy(decal.gameObject, 5f);
    73.                         }
    74.                 }
    75.  
    76.                 //if (audioEffect)
    77.                 //    AudioSource.PlayClipAtPoint(audioEffect, col.contacts[0].point);
    78.             }
    79.         }
    80.     }
    81. }
    82.  
    How can I make this bullets compatible with the asset ?
    Is this possible ?
    Thanks you by advance
     
  31. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818

    Hello,

    Try adding in the line

    Code (CSharp):
    1. col.gameObject.SendMessage("Damage", baseDamage, SendMessageOptions.DontRequireReceiver);
    inside the Effect method. So:

    Code (CSharp):
    1. void Effect(Collision col, bool ENTEREXIT)
    2.     {
    3.         for (int i = 0; i < impactEffects.Count; i++)
    4.         {
    5.             BulletImpactEffect impactEffect = impactEffects[i];
    6.  
    7.             if (col.gameObject.tag == impactEffect.hitObjectTag || col.gameObject.HasTag(impactEffect.hitObjectTag))
    8.             {
    9.                 GameObject clone = null;
    10.                 GameObject particleEffect = ENTEREXIT ? impactEffect.impactParticle : impactEffect.exitParticle;
    11.                 //AudioClip audioEffect = ENTEREXIT ? impactEffect.impactAudio[Random.Range(0, impactEffect.impactAudio.Length - 1)] : impactEffect.exitAudio[Random.Range(0, impactEffect.exitAudio.Length - 1)];
    12.  
    13. //Maybe here?
    14.                    col.gameObject.SendMessage("Damage", baseDamage, SendMessageOptions.DontRequireReceiver);
    15.  
    16.                 if (particleEffect)
    17.                 {
    18.                     clone = Instantiate(particleEffect,
    19.                         col.contacts[0].point + col.contacts[0].normal * 0.01f,
    20.                         Quaternion.FromToRotation(Vector3.forward, col.contacts[0].normal)) as GameObject;
    21.  
    22.                     Destroy(clone, 3f);
    23.  
    24.                     Transform decal = clone.transform.GetChild(0);
    25.  
    26.                     if (decal)
    27.                         if (decal.name == "Decal")
    28.                         {
    29.                             decal.SetParent(col.transform, true);
    30.                             Destroy(decal.gameObject, 5f);
    31.                         }
    32.                 }
    33.  
    34.                 //if (audioEffect)
    35.                 //    AudioSource.PlayClipAtPoint(audioEffect, col.contacts[0].point);
    36.             }
    37.         }
    38.     }
    Hopefully I didn't screw up the brackets there. Let me know if this works! :)
     
  32. pierre92nicot

    pierre92nicot

    Joined:
    Aug 21, 2018
    Posts:
    57
    Hi, thanks for your help,
    at first it wont work, I had to add the code you gave me

    Code (CSharp):
    1. col.gameObject.SendMessage("Damage", baseDamage, SendMessageOptions.DontRequireReceiver);
    2.  
    here :

    Code (CSharp):
    1.   void OnCollisionEnter(Collision col)
    2.     {
    3.         Effect(col, true);
    4.         Destroy(gameObject, 0.02f);
    5.     }
    Now it works !
    Thank you for the great support
     
    squared55 likes this.
  33. musolo

    musolo

    Joined:
    Sep 12, 2014
    Posts:
    238
    Hi squared55!
    Could you talk about performance mode, what parts of agent functionality being disabled when it`s activated?
    What are the performance gains percentage wise(approximately)?
    Thanks!
     
    Last edited: Oct 5, 2018
  34. pierre92nicot

    pierre92nicot

    Joined:
    Aug 21, 2018
    Posts:
    57
    Hi,
    Is there a way to play a sound, when a TacticalAI bullet collide with something ?

    Thanks by advance
     
  35. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    If my memory is correct, it should disable dynamic cover, melee, sprinting, high-quality aiming, and dodging. Basically, they just move and shoot. Also, it sets the AI Cycle to once every 2 seconds, as opposed to the fractions of a second you'd probably want when not using performance mode.

    Also, I should note that everything that all these can disabled/set by changing the various individual settings, checking that box is just a shortcut.

    I haven't run any formal tests as the exact performance gain will vary greatly between different variable settings and levels, making pretty much any test I could run fairly useless for anything except the specific scenario I had up at the moment. The best and quickest way to determine the change on your set-up would be to simply open up the Unity profiler and run a test yourself. :)

    Attach a sound effect to your hit effect/bullet hole prefab.
     
    Last edited: Oct 7, 2018
  36. pierre92nicot

    pierre92nicot

    Joined:
    Aug 21, 2018
    Posts:
    57
  37. pierre92nicot

    pierre92nicot

    Joined:
    Aug 21, 2018
    Posts:
    57
    I am using a big outdoor terrain; is there a way to make the AI Agents feet touch the ground instead of flying 20 centimeter above the ground ?

    Have you some advice for making the AI Agents to be more careful for their life and more realistic? (make them use more cover for example)

    Have you some advice for improving performance on big AI populated maps (50 AI Agents) ?
    I have tried to set the AI cycle to 0.7 but the performance mode on the AI Controller make the AI Agent not capable of Aiming correctly

    Often, my AI Agent get team killed and I am not sure how to avoid that...

    Thanks you for your awesome asset.
     
  38. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Make sure that your navmesh baking settings uses a height mesh, so that it hugs the terrain. You can also select the agent ragdoll and move it downward relative to the parent object (with all the scripts on it). This should make it lower during the game.

    The best way to make them use more cover would be to simply put more manually placed cover nodes on your map. You can also increase the time the agent stays in cover in their script settings. Increasing the time between volleys will also make them duck their heads in longer.

    As for performance, by biggest recommendations are:
    -Reduce the rate of fire for your agents.
    -Use a lower-polycount character model, if you have one.
    -Further increase the AI cycle time (go as low as you can before the behavior gets unacceptable. At extreme distance, you'll have a lot more leeway before the AI starts to look too stupid)
    -Make sure you are using the latest version (there was a huge performance bug relating to sprinting that I fixed a couple versions ago).
    -Disable dynamic cover.
    -If possible, design your levels such that you can throw the agents at the player in waves, rather than all at once.

    You can put the AI agents on a different physics layer that is not included in the bullet layermask so that any wayward friendly bullets pass right through them.
     
  39. pierre92nicot

    pierre92nicot

    Joined:
    Aug 21, 2018
    Posts:
    57
    Hi,
    I am setting up a scene on a very large map, in VR, with 50 AI and thanks to you the performance are good so far now.

    Is there a simple way to make an AI follow the player ?
    Using the player as a key transform for the BasicAI script didnt work.

    I also noticed that the AI shots exactly at the same time when a fight start (10 first second), probably due to the AI cycle.
    Can I avoid that ?

    Thanks for the amazing support.
     
  40. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    To make the agent follow more the key transform more closely, swap the idle behavior with MoveToPoint, and the combat one with Berserker.

    The current code doesn't have a way to offset the agents initial firing time. However, after that first burst, the randomization should stagger them further. Maybe later I can look into a quick code modification that would allow the first shots to be more spread out.
     
    pierre92nicot likes this.
  41. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    Hi
    squared55,

    I have a similar problem to this issue which was posted previously by desertGhost :

    "I have an issue related to the Rotate to Aim Gun Script and my agent's firing animation. The firing animation that I am using has a large amount of recoil. This recoil makes the bullet spawn object point into the air, which causes the Rotate to Aim Gun Script to rotate the agent's spine bone downward. This makes the agent hunch over every time a shot is fired. How should I approach modifying the Rotate to Aim Gun Script to fix this?"

    Effectively we have in my case at least an issue that when we have custom Enemy Characters they are unable to target the Player (notwithstanding other Teams) properly/correctly or however you want to describe it.

    i.e. there are two options so it seems with no way for Either or any to adjust the Characters so they/their weapon/bullet will Target the Player correctly in a manner which is acceptable in a Game.

    1. We can use High Quality Aiming setting where the weapon Bullet will try and target the Player correctly but the Enemy Character and weapon point towards the Ground very near to the Enemy which is extremely off putting for any game Player and us game devs too. Which I guess is why High Quality Aiming exists in an attempt to correct the issue?


    2. If we turn off High Quality Aiming then the Enemy does not Target (rotate to and aim weapon at ) the Floor and the Character Movement/Pose is correct - however in this instance the bullet/tracer again does not Target the Player and does not hit/damage the Player.

    The setting we have of Accuracy Parameters does not and cant compensate for this so we have no option at all and have choices none of which actually work to control these things. I have been trying all settings and adjustments for months and it cant be done out of the box at least and it should be so.

    What I want to ask, know is why does the Character not actually Target the Player and why the Bullet/Tracer particularly does not Target the Player? at whatever position he is. It does not seem to trace to the Player at all if one is not in High Quality Aiming?

    And how can we fix this sensibly? I have not found a workaround yet? That is not well it may work or try this or that?

    Clearly the asset should allow for this as that s what its all about - one character targeting and shooting another not missing them with a bullet.

    :)

    Peter


     
  42. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Basically, when the agent rotates, the bullet spawn traces a circle around the spine. When the target gets too close or inside this circle, the gun can't point at the target and the resulting behavior is what you see. So, you'll probably want to reduce the radius of this circle.

    So, try duplicating the bullet spawn object and moving the duplicate back towards the spine, but such that it is still pointing along the same axis as the bullet spawn. Then, set this new duplicate object as the Bullet Spawn Transform in the RotateToAimGunScript.

    Additionally, if you haven't already, try attaching the player's target script to the first person camera, rather than the body. If neither of these solve the problem, please post a screenshot of the issue. :)
     
    Last edited: Oct 17, 2018
  43. pierre92nicot

    pierre92nicot

    Joined:
    Aug 21, 2018
    Posts:
    57
    Hi again,
    is there a simple way to change the AI combat behaviour when the player press a button ?
    Now that the AI follows me, I want them to switch between Berserker (so they can follow me) and Tactical ( so they can look for the closest cover)
    I am not sure if i have to use the custom behaviour script.
     
  44. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    You'd have to use the same method as swapping a custom behavior. This will require a bit of scripting on your end, and the method should be outlined in the manual.
     
  45. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    Hi squared55,

    Thanks for the reply.

    Yes I have been trying to understand exactly how this works or is supposed to work given that we have a system where the Enemy NPC Characters Upper Body is designed to Rotate? and that includes in the Vertical Axis Yes.

    However the issue for me and others I guess as I see it is (irrespective of the bullet) the Upper Body of the Enemy NPC is not rotating to Player "when the agent rotates" (but pointing at the ground) - when using High Quality Aiming setting and the question is why is this when as said the system is designed to Rotate the Upper Body?

    The Gun and Bullet is secondary is it not if we cant get the Upper Body to Rotate? We don't need the Gun and Bullet being accurate if the Upper Body itself is still Pointing at the Ground do we. as then not all parts i.e. Upper Body, weapon, bullet/flash are not all coherently aligned and aiming (looking) at the target? All these parts should be working together at the end of the day so all visually are pointing towards the Player Target (or other target) and the bullet then moves to the Target - when the weapon is fired. What we have now is the bullet can aim at and move to target in High Quality Aiming but the other items Upper Body and Weapon are not rotating to the Target. The Player Upper Body and weapon pointing to the ground and the bullet spawning from a ground level position and the bullet moving from the ground position or thereabouts at an acute angle not aligned with the weapon towards the player.

    Your reply does not relate to the issue as far as I can see as its the Player Upper Body is the issue. Why does is not rotate to Player? in the vertical when that's what it is supposed to do? or should do presumably as that is usually what happens when a person fires a weapon at a target he don't normally look at the floor when the target is not there. Unless of course that's where the target is :)

    Unless I am missing something here your reply relates more to the accuracy of the bullet which is not going to fix the NPC Enemy looking and aiming his weapon at the ground in front of himself.

    Of course as said previously if not using the High Quality Aiming Setting then the Enemy Upper Body does not look at the ground when shooting but conversely the bullet is not accurate so I seem to need a mix of targeting methods :)

    Anyway Perhaps I am not understanding what you refer to above and how that might correct the Upper Body Rotation as opposed to the Gun and Bullet. The Gun if you mean should rotate as in your demo and default examples then the weapon (Gun) is not positioned correctly in the Enemy NPC's hands and does not sit in them correctly - the default gun points upwards from the Enemy Hands again which would then need correcting. Perhaps that's where the issue lies.

    "Basically, when the agent rotates, the bullet spawn traces a circle around the spine. When the target gets too close or inside this circle, the gun can't point at the target and the resulting behavior is what you see. So, you'll probably want to reduce the radius of this circle."

    What target are you referring to here? Player or other team? if so the the Player cant be too close causing this as my enemies tend to be a long way off in my open world levels where I try to keep the well away from the Player. :)

    I will try and look at your suggestions and see if they might help if indeed they would relate to or have influence on the Upper Body Rotation in the vertical of the Enemy NPC's.

    Thank you.

    Peter
     
    Last edited: Oct 18, 2018
  46. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Only the upper body rotates, but it rotates in order to point the bullet spawn at the target, not to point the upper body at the target. This is an important distinction and is why the position and orientation of the bullet spawn is relevant.

    The target is whatever the agent is trying to hit. In your case, it seems to be the player. It is aimed at the object's origin in space which is marked by the transform gizmo when the object mode is set to pivot. If this is at the player's feet, then the agent will aim at the player's feet. See the picture below. The agent will aim at the transform gizmo, rather than the mesh because that's where the origin is.

    aimpoint.png

    This is why I recommend attaching the target script to the first person camera (and removing the old one), as the camera will be at the top of the body rather than at the floor, as is the case with some player controllers. Additionally, make sure you remove the old target script from your player, otherwise the agents may decide to target the old one anyways.

    ---

    Additionally, the Max Firing Angle should allow the the bullets to fire directly at the target (with bullet spread added) if the agent is aiming "close enough," but not straight ahead. This "close enough" angle is determined by the Max Firing Angle. From the sounds of it, increasing the value of this variable under the accuracy parameters in the Gun Script in combination with disabling High Quality Aiming could solve your issue.

    ---

    You may also want to try increasing the Max Iterations value in the RotateToAimGun script while having High Quality Aiming enabled. The "Min Angle" value should also be very low; close to 0.

    ---

    You should also make sure that the forward axis/blue arrow of the bullet spawn is facing the front of the gun, as demonstrated in the pictures below.

    ---

    Finally, it seems as though I may have misunderstood you when you said "Bullet will try and target the Player correctly but the Enemy Character and weapon point towards the Ground very near to the Enemy." I thought that you meant that the issue only occurred when the player got close to the enemy, but upon re-reading, I see that may not be the case. Nonetheless, I made these quick images to show what my suggested change from the last message does:

    PROPER BEHAVIOR:
    Distance.png

    WHEN TARGET GETS TO CLOSE:
    Too Close.png

    WITH BULLET SPAWN TRANSFORM PULLED BACK:
    Better.png

    ---

    Oh, and make sure to disable performance mode when trying to fix the issue, to ensure that the variable changes you make actually take effect!

    ---

    Finally, if nothing thus far helps, can you please post screenshots so that I can better understand the issue? Also, does the problem occur in the demo agents, or just custom agents you have made?
     
    Last edited: Oct 21, 2018
  47. Tretiak

    Tretiak

    Joined:
    Jan 22, 2018
    Posts:
    49
    Im using waypoints transform for patroling points, which AI is following. Is it possible to stay some time at every point, before starting move to another ? Like patrol with staying on every waypoint some time. Thanks
     
  48. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    That would require a bit of modification to the Patrol behavior's code. Next time I get a chance I'll see if I can make a modified version for you.

    Also, I just uploaded a version which should support UFPS 2, with no code changes required on your end. Let me know if there's any problems with the integration. :)


    EDIT:

    OK, try this for the patrolling:

    ---See fixed/improved version below---

    Put that in a new C# script called "PatrolWithTimer", put it on your agent and set the "BehaveLevel" variable to Idle. Then set the timeToWaitAtEachPoint to your desired time value. Let me know if it works! :)
     
    Last edited: Nov 1, 2018
    Tretiak likes this.
  49. Tretiak

    Tretiak

    Joined:
    Jan 22, 2018
    Posts:
    49
    Hey, thanks for answer and script. I crečated script with your code, put on AI, set patrol behavior, set 3 transforms as points. When i run, game always crashes after i did that. Im using 2018.3.05 unity.
     
  50. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    OK, try this instead. This works on my computer.

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. namespace TacticalAI
    7. {
    8.     public class PatrolWithTimer : TacticalAI.CustomAIBehaviour
    9.     {
    10.  
    11.         bool haveAPatrolTarget = false;
    12.         int currentPatrolIndex = 0;
    13.         float patrolNodeDistSquared;
    14.  
    15.         public void Awake()
    16.         {
    17.             base.Initiate();
    18.             targetVector = transform.position;
    19.             timeUntilNextPoint = timeToWaitAtEachPoint;
    20.         }
    21.  
    22.         public float timeToWaitAtEachPoint = 5.0f;
    23.         float timeUntilNextPoint = 5.0f;
    24.  
    25.         public override void AICycle()
    26.         {
    27.             if (baseScript.patrolNodes.Length >= 0)
    28.             {
    29.                 //if we don't have a current goal, find one.
    30.                 if (!haveAPatrolTarget)
    31.                 {
    32.                     SetPatrolNodeDistSquared();
    33.                     targetVector = baseScript.patrolNodes[currentPatrolIndex].position;
    34.                     haveAPatrolTarget = true;
    35.  
    36.                     //Move the current patrol node index up and loop it around to the beginning if necessary
    37.                     currentPatrolIndex++;
    38.                     if (currentPatrolIndex >= baseScript.patrolNodes.Length)
    39.                     {
    40.                         currentPatrolIndex = 0;
    41.                     }
    42.                 }
    43.                 //if we have one, check if we're to close.  If so, cancel the current goal.
    44.                 else if (Vector3.SqrMagnitude(targetVector - myTransform.position) < patrolNodeDistSquared)
    45.                 {
    46.                     timeUntilNextPoint -= baseScript.cycleTime;
    47.                     if (timeUntilNextPoint <= 0)
    48.                     {
    49.                         haveAPatrolTarget = false;
    50.                     }
    51.                 }
    52.  
    53.                 if(Vector3.SqrMagnitude(targetVector - myTransform.position) > patrolNodeDistSquared)
    54.                 {
    55.                     timeUntilNextPoint = timeToWaitAtEachPoint;
    56.                 }
    57.             }
    58.             else
    59.             {
    60.                 Debug.LogError("No patrol nodes set!  Please set the array in the inspector, via script, or change the AI's non-engaging behavior");
    61.             }
    62.         }
    63.  
    64.         void SetPatrolNodeDistSquared()
    65.         {
    66.             patrolNodeDistSquared = baseScript.closeEnoughToPatrolNodeDist * baseScript.closeEnoughToPatrolNodeDist;
    67.         }
    68.  
    69.     }
    70. }
    71.  
    Make sure every entry in the patrol array has a gameobject in it too. Empty/null slots can cause problems.
     
    Last edited: Nov 3, 2018
    tcmeric likes this.