Search Unity

Shooter AI – The Ultimate Artificial Intelligence Solution

Discussion in 'Assets and Asset Store' started by nikita68, Oct 8, 2013.

  1. emmcd3

    emmcd3

    Joined:
    Dec 16, 2012
    Posts:
    26
    Glad to help, Nikita...
     
    Last edited: Oct 25, 2014
  2. thendricks

    thendricks

    Joined:
    Aug 14, 2012
    Posts:
    48
    Ahh, thanks
     
  3. emmcd3

    emmcd3

    Joined:
    Dec 16, 2012
    Posts:
    26
    That worked very nicely. Thanks
     
  4. mateodon

    mateodon

    Joined:
    Oct 1, 2013
    Posts:
    39
    Could you do an updated video on melee in 2.0?

    I cant get my AI to do more than dance around each other. After lunch I'll find a proper melee animation and big sword to see if it's just a matter of the collider missing the target, but it does feel like I'm not setting up the behavior properly, EDIT: yeah, no luck, swords go right through the opponent but no damage dealt.

    Also, what handles the knockdown from the bullets? I wanted to see how the demo soldiers would handle a boss with high health, but every shot knocked him to the ground so the soldiers easily killed him at 10, 100 and even 1000 health.
     
    Last edited: Oct 26, 2014
  5. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    The guys are still not holding the guns perfectly at times, it seems sometimes his arms sort of go behind his back when he fires.. Im still messing with the IK and the new tutorial but any advice would be good, see pic!

    Also the demo soldier's feet seem to go through the floor, I cant find the main capsule collider to adjust, where is it?

    New version is looking great so far, much nicer than the previous one :)
     

    Attached Files:

    Last edited: Oct 27, 2014
  6. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @everybody - I'm currently on holiday so I will be much slower in responses and can't offer any fixes until next week.

    @emmcd3 - what exactly did you change? I would like to know if we can integrate it into our main version.

    @mateodon - Will Do. The new melee system is a bit more complicated that before.

    @radiantboy - have you checked out the newest ik tutorial? It explains some main setup features. If that still continues go to "Gateway Games Weapon Manager" -> "Max Weapon angle" -> Set it lower. This reduces the Max angle St which the weapon can be wielded. If the setup is incorrect this sometimes plays an important role.


    Edit: woops forgot your other question :)
    If you want to adjust the height, go into the main character and adjust the NavmeshAgent height and offset. We don't use colliders directly but use navigation agents to determine the actual soldier data.

    Thanks!
     
    Last edited: Oct 30, 2014
  7. CreatureSurvive

    CreatureSurvive

    Joined:
    May 3, 2014
    Posts:
    17

    I found that fixing the Ragdoll colliders to fit the model better has helped with this a lot.
     
  8. SuperNewbee

    SuperNewbee

    Joined:
    Jun 2, 2012
    Posts:
    196
    Is there any instructions at all on how to make this work with Realistic FPS prefab? Could not find it in the manual or video tutorials. It says works out of the box but an unable to find any mention of instructions to make them work together. Would really like to get this working.
     
  9. thenamesace

    thenamesace

    Joined:
    Jan 25, 2014
    Posts:
    157
    Same here i have tried and failed ufps is working but i feel we have been mis-sold under the "works out of the box" quote
     
  10. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @Everybody

    I'm back from a great holiday and have made 3 new tutorials today!

    Melee:


    RFPS Integration:


    A new UFPS/SAI converter:


    Tell us which tutorials you want and we'll make them!

    We're currently developing cool new features geared towards weapon tactics. Also stay tuned for some epic news coming soon regarding UFPS ;)

    @CreatureSurviive -
    What exactly did it help?

    @SuperNewbee & shaunmckay12 -
    Just got a tutorial out :)
     
    thenamesace likes this.
  11. PunkMunkey

    PunkMunkey

    Joined:
    Nov 4, 2014
    Posts:
    2
    Hey I'm having a bit of a problem with the ragdoll script in SAI2.0. Our game involves the AI occasionally getting hit by a vehicle which then ragdolls them and sends them flying (which is fantastic). However we want them to get back up (which they do) but the problem is that the AI tweens back to the original position that it was initially struck by the vehicle instead of getting from where it stopped ragdolling. This results in them sliding 10-20 meters while the getting up animation is played and it looks pretty bizarre. Any fixes for this?
     
  12. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @PunkMunkey -
    In "GatewayGamesRagdollHelper.cs", replace lines ~200 with the following:
    Code (csharp):
    1.  
    2. transform.rotation = Quaternion.Lerp( transform.rotation, transform.parent.rotation, 0.1f);
    3.                    
    4.             if(state == RagdollState.blendToAnim)
    5.             {
    6.                 transform.parent.position = transform.position - transform.localPosition;
    7.                 transform.localPosition = Vector3.zero;
    8.             }
    9.             else
    10.             {
    11.                 transform.position = Vector3.Lerp( transform.position, transform.parent.position, 0.5f);
    12.             }
    13.  
     
  13. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @Everybody!

    Shooter AI Multiplayer 2.0 has been sent out, and should be on the asset store in the next few days! As warned before, the price of it will go up to $70.
     
  14. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    is there a way to programatically make a character in shooterai? Or can I take a one that exists in my scene already and swap out the model for another using code at runtime? Im using UMA, it can generate decent optimised people and crowds out, now I want to write some code that will make them into my enemies basically. Would be cool to generate crowds of enemies this way!!.. Any tips would be good, im experimenting now :)

    Edit: So I found UMA Power tools it lets you make a prefab of the UMA guys, I ragdolled one and made him a shooter AI character, it worked!! Except... that he doesnt actually animate properly, sort of glides around like he isn't a mecanim rig, yet when I go to select prefab to find the tab to see if that is the case, I cant see the import options where you can normally swap this. Something weird is happening, but Im very close, any thoughts on why this doesnt animate? See screenshot :)

    Interestingly, if I shoot them, they collapse like real ragdolls, and when they get up again they're pretty much working and animating properly, the head is a bit weird but the rest seems to work, but only after I have shot them down once!..
     

    Attached Files:

    Last edited: Nov 4, 2014
  15. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @radiantboy -
    Very nice!
    My opinion on what is going on:
    1) The avatar isn't set correctly on the animator on the model.
    2) The head IK is screwing something up very, very much :D

    I recommend looking under the import settings if the avatar has been generated and whether its set in the animator. I persoanlly don't think that the head IK is at fault as its literally one line of code.
     
  16. uvavoo

    uvavoo

    Joined:
    Oct 15, 2007
    Posts:
    60
    "The guys are still not holding the guns perfectly at times, it seems sometimes his arms sort of go behind his back when he fires.. Im still messing with the IK and the new tutorial but any advice would be good, see pic!" radiant boy

    Yes, I'm having the same problem with the soldier prefab. Looked at the tutorial, tried lowering the max angle of the gun, but can't seem to fix it. Seems to happen when, for example, the player runs around the back of the soldier and as the soldier is turning he tries to point the weapon at the player, giving a weird effect as his arms cross over backwards. Any other suggestions on how to fix this?

    Other than that, this version is looking great and I have easily integrated it into my game.
     
  17. emmcd3

    emmcd3

    Joined:
    Dec 16, 2012
    Posts:
    26
    @Nikita
    @emmcd3 - what exactly did you change? I would like to know if we can integrate it into our main version.

    which change are you referring to ? ...the Tag issue, perhaps?
     
  18. emmcd3

    emmcd3

    Joined:
    Dec 16, 2012
    Posts:
    26
    On another topic, I think it would a great bit of value added if bridges into the Behavior Designer and Playmaker apps
    was something of a priority. At least at the schematic level, I have these conceptualized where the strongest attributes of both should be used.

    What are your thoughts on this topic. I thought I saw something about it earlier.
     
  19. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @Everybody!
    Shooter AI Multiplayer is officially out, using SAI 2.0.1!

    @uvavoo - Just noticed the bug. Will be looking at a fix coming with 2.0.1. I'm really glad that you like 2.0 :)

    @emmcd3
    Sorry, i think i misread something. :D

    I never knew people wanted BD/PlayMaker integration really. I'll definitely look into it and see if we can integrate in 2.1.
     
  20. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    I sort of abandoned this asset months back mainly because of issues with the AI holding their guns all screwy. I came back today to check things out to see if there have been any improvements. It looks like even with a new version and new IK system the AI still does very weird things. I guess even Partel Lang cannot help with this asset's IK...

    Sorry to be harsh but there seems to be something fundamentally wrong with the way this asset is developed. Almost like the dev focuses on coding and marketing, but does very little (if any) actual testing... everything is supposed to work "out of the box" but even the asset's own demo doesn't work correctly... see below... there are issues with the way the rifles are held, feet penetrating the ground, etc.

    I really want to like this asset so I'll hold off on any negative reviews to see if the dev can turn things around at last.

    These images are directly taken from ShooterAI's own demo at https://dl.dropboxusercontent.com/u/86419401/Demos/V2/SAI-UFPS/SAI-UFPS.html

    ShooterAI.png
     
  21. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @eridani -
    Thank you for giving us real criticism. I actually agree with you that with the initial 2.0 launch we really rushed the release. Also we kind of made the ufps demo in like 5 mins, as we're currently making a really nice new demo showing off the better side.

    Regarding the bug you showed in the Screenshots, I literally just been able to recreat it yesterday and am now working on the fix for 2.0.1. The big issue is that the ai isn't measuring the angle correctly at which it should hold its weapon.

    To be honest, I believe the best improvement would be if we could have a dedicated testing team, for all future releases, as we have very little time for testing due to parallel projects and school.

    Thank you very much for the time you invest in giving us feedback, and still not giving up on us. :)
     
    hopeful likes this.
  22. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Yeah, sorry if I came off like a jerk. It's just that it seems like this same gun-holding weirdness has been one of the main things plaguing this asset for half a year, and it seems like you guys keep saying it's fixed when it's not. Anyway, thanks for your calm response, and hope you get the bugs ironed out this time... this asset seems like it's ALMOST there, which would make it such a fantastic drop-in AI solution. Keeping my fingers crossed =)
     
    hopeful likes this.
  23. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @Everybody with the weapon through body bug -
    In liine 184 of GatewayGamesWeaponManager.cs, replace it with the following code:
    Code (csharp):
    1.  
    2. (brain.eyes.canSeeEnemy == true || brain.ears.canHearEnemy == true) && Vector3.Angle( transform.forward, engageWeaponHoldingLocation.forward) < maxWeaponAngle)
    3.  
    Also, set maxWeaponAngle to something like 60-70 for best results. Please tell me if this works for you.

    @eridani -
    Don't worry, i don't take this personally. :)
    This issue has been giving me so many headaches in the last year. The problem with it, is that one little bug crashes the whole system. We're trying to crush them, hopefully this being the final stretch until it finally fully works.

    Seriously, thank you for sticking around.
     
  24. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    I'm sticking around because I really want to use this asset in my apps! =) I'll give that fix a shot soon. Could you also take a look at the feet penetrating the ground (see the last picture I posted)? Thanks for all your hard work!
     
    nikita68 and hopeful like this.
  25. uvavoo

    uvavoo

    Joined:
    Oct 15, 2007
    Posts:
    60
    Tested this change to the script and unfortunately didn't work at all for me. Still exactly the same problem.
    This problem seems to happen to me when player is close to the enemy.
    Gun seems to stay in same place in 3d space as character turns.

    Request. Also on another note. I would like, if possible to have a box which says something like 'minimum distance to player'. So the enemy doesn't come closer to the player than this distance (0 of course if the player has a melee attack).

    When the enemy comes very close to the player, the ai seems to become a bit odd. I don't think it likely in real life that the enemy would come and wander around at very close proximity to the player. He would rather keep his distance and shoot from there.

    Also a question about cover seeking.
    What invokes cover seeking behaviour? I can shoot at the enemy from a distance and hit him, and he doesn't seem to react. I would expect him to seek cover when he has received damage (or a certain amount of damage).

    I would be happy to test various iterations of this asset.
     
  26. uvavoo

    uvavoo

    Joined:
    Oct 15, 2007
    Posts:
    60
    Cover seeking.
    I thought i would try to use the predefined cover system.
    I created three positions. when playing the game these predefined positions disappeared! Is this a bug.? Or am I missing something?
     
  27. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    I came here to post about whether cover is still in this, cant find any mention of it anywhere in manual - cant seem to find info on the layers required too, which are they for navigation? Wall Obstacle and Floor?
     
    Last edited: Nov 11, 2014
  28. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @uvavoo -

    1) We're working on the fix.
    2) Great idea! I'll add minimum distance in 2.0.1.
    3) Cover seeking is invoked usually when hit too much, or the AI thinks the situation is too risky.

    4) Have you watched the setup tutorial?

    I just tried out the cover system, and it works for me:
    https://www.dropbox.com/s/y1d13jjh85fqzze/predefined-cover.png?dl=0

    @radiantboy -

    1) We have a few tutorials for the cover finding, but there is no specific documentation as of now. We're also currently merging our cover system with a new one.


    2) What do you mean with layers? SAI always uses default.

    Thanks!
    Nikita
     
  29. 99thmonkey

    99thmonkey

    Joined:
    Aug 10, 2012
    Posts:
    525
    Do I need Final IK to use with this new update? If so, is it easy to use together?
     
  30. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @99thmonkey - Nope. We actually licensed out a part of FinalIK. That was the bulk of the production cost of SAI 2.0 :D
     
    Razmot likes this.
  31. 99thmonkey

    99thmonkey

    Joined:
    Aug 10, 2012
    Posts:
    525
    Sounds nice. Do I have the ability to manually put the weapon(s) in the AI's hand (mainly the melee ones) so they are positioned the way I want? Maybe I just need to create a new project and play around with this.
     
  32. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    We have a whole tutorial on it:


    I recommend watching them all, so that you really get a good grasp of SAI.

    @uvavoo -

    Could you try replacing the code in GatewayGamesWeaponManager with this:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6.  
    7. namespace GatewayGames.ShooterAI
    8. {
    9.    
    10.     /// <summary>
    11.     /// Types of weapon.
    12.     /// </summary>
    13.     public enum FireType { Ranged, Melee };
    14.    
    15.    
    16.     /// <summary>
    17.     /// Contains data vital for multiple weapons.
    18.     /// </summary>
    19.     [System.Serializable]
    20.     public class WeaponData
    21.     {
    22.         /// <summary>
    23.         /// Reference to the weapon object
    24.         /// </summary>
    25.         public Transform weaponObject;
    26.            
    27.     }
    28.    
    29.    
    30.    
    31.     /// <summary>
    32.     /// Data about the secondary, throwable weapon, e.g. grenade.
    33.     /// </summary>
    34.     [System.Serializable]
    35.     public class SecondaryWeapon
    36.     {
    37.         /// <summary>
    38.         /// the secondary weapon prefab that gets thrown, e.g. a grenade
    39.         /// </summary>
    40.         public Rigidbody secondaryWeaponPrefab = null;
    41.        
    42.        
    43.         /// <summary>
    44.         /// the amount of the secondary weapon.
    45.         /// </summary>
    46.         public int secondaryWeaponAmount = 3;
    47.        
    48.        
    49.         /// <summary>
    50.         /// the throw force for the secondary weapon
    51.         /// </summary>
    52.         public float throwForce = 100f;
    53.        
    54.        
    55.         /// <summary>
    56.         /// The throw vector.
    57.         /// </summary>
    58.         public Vector3 throwVector = Vector3.up + Vector3.forward;
    59.        
    60.        
    61.         /// <summary>
    62.         /// The trigger distance under which to throw the weapon.
    63.         /// </summary>
    64.         public float triggerDistance = 10f;
    65.        
    66.        
    67.         /// <summary>
    68.         /// The time when a secondary was last thrown.
    69.         /// </summary>
    70.         public float lastThrowTime = 0f;
    71.     }
    72.    
    73.    
    74.     /// <summary>
    75.     /// IK targets.
    76.     /// </summary>
    77.     [System.Serializable]
    78.     public class IKTargets
    79.     {
    80.         /// <summary>
    81.         /// The left hand target.
    82.         /// </summary>
    83.         public Transform leftHandTarget;
    84.        
    85.         /// <summary>
    86.         /// The right hand target.
    87.         /// </summary>
    88.         public Transform rightHandTarget;
    89.        
    90.     }
    91.    
    92.    
    93.    
    94.     /// <summary>
    95.     /// The AI's weapon manager.
    96.     /// </summary>
    97.     public class GatewayGamesWeaponManager : MonoBehaviour
    98.     {
    99.        
    100.        
    101.        
    102.        
    103.         public bool debug = false; //whether to debug or not
    104.         public Vector3 aimTargetPos = Vector3.zero; //the target at which to aim
    105.         public Transform currentHoldingWeapon = null; //the weapon we're currently holding
    106.         public FireType currentWeaponFiretype = FireType.Ranged; //the firing type of the current weapon
    107.         public IKTypes currentWeaponIK = IKTypes.BothHands; //the IK setting of the current weapon
    108.         [ Range( 0, 180f) ]
    109.         public float maxWeaponAngle = 40f; //the max angle of the weapon until the AI turns as a whole
    110.         public IKTargets currentIKTargets = new IKTargets(); //the IK targets
    111.         public Transform defaultWeaponHoldingLocation = null, engageWeaponHoldingLocation; //the default parent under which to hold the gun
    112.         public HumanBodyBones bodyPartHoldingReference = HumanBodyBones.RightHand; //the reference for where to hold the weapon
    113.         [Range( 0f, 1f)]
    114.         public float engageTime = 0.2f; //the speed with which the ai can aim its camera
    115.         public List<WeaponData> multipleWeapons = new List<WeaponData>(); //the weapons that this ai can use; must be referenced to deactivated weapons inside the AI
    116.         public SecondaryWeapon secondaryWeaponData = new SecondaryWeapon(); //the data about the secondary throwable weapon, e.g. grenade
    117.         public float weaponAngle = 0f;
    118.        
    119.         [HideInInspector]
    120.         public Transform IKBendGoalLeft;
    121.        
    122.         [HideInInspector]
    123.         public float meleeAttackDistance = 0.5f; //the attack distance for the current melee weapon
    124.        
    125.        
    126.    
    127.         private GatewayGamesBrain brain; //brain reference
    128.         private RaycastHit weaponSeeEnemyData; //used to determine whether the weapon can see the enemy
    129.         private Vector3 aimTempPos; //the temp position of where we're aiming; used for learping
    130.        
    131.        
    132.         void Awake()
    133.         {
    134.             //set caches correctly
    135.             brain = GetComponent<GatewayGamesBrain>();
    136.            
    137.             //set variables
    138.             LateUpdate();
    139.         }
    140.        
    141.        
    142.         void OnDestroy()
    143.         {
    144.             //apply last update before destruction (e.g. death)
    145.             LateUpdate();
    146.         }
    147.  
    148.         public Quaternion recoilOffset { get; private set; }
    149.         public float engageFactor /*{ get; private set; }*/;
    150.         public float arbitraryFactor { get; private set; }
    151.         private float engageTarget = 0f;
    152.  
    153.         [HideInInspector] public Transform arbitraryHoldingLocation;
    154.         private Transform lastArbitraryHoldingLocation;
    155.         private float arbitraryVel;
    156.         private float engageVel;
    157.  
    158.         private float SmoothDampSnap(float current, float target, ref float currentVelocity, float smoothTime, float snap) {
    159.             float x = Mathf.SmoothDamp(current, target, ref currentVelocity, smoothTime);
    160.             if (Mathf.Abs(x) < snap) return 0f;
    161.             if (Mathf.Abs(x - 1f) < snap) return 1f;
    162.             return x;
    163.         }
    164.  
    165.         void LateUpdate()
    166.         {
    167.            
    168.            
    169.             //set variables correctly
    170.             if(currentHoldingWeapon != null)
    171.             {
    172.                 //get weapon angle, based on whether we're yielding the weapon or not
    173.                 weaponAngle = (brain.currentState == CurrentState.Engage || brain.currentState == CurrentState.Investigate ) ?
    174.                     Vector3.Angle( transform.forward, currentHoldingWeapon.forward) : 0f;
    175.                
    176.                 //set aiming correctly with smoothing
    177.                 if(aimTargetPos != Vector3.zero) // @todo what if the character IS supposed to be aiming at Vector3.zero?
    178.                 {
    179.                     //check if we need to turn, rotate the character before everything else
    180.                     if( weaponAngle > maxWeaponAngle && brain.movement.movementData.enRouteToDestination == false)
    181.                     {
    182.                         //turn towards where the weapon is facing
    183.                         Vector3 direction = aimTargetPos - transform.position;
    184.                         direction.y = 0f;
    185.                         transform.rotation = Quaternion.Lerp( transform.rotation, Quaternion.LookRotation(direction), 0.1f);
    186.                     }
    187.                 }
    188.                
    189.                 //determine the engage aiming state
    190.                 if( (brain.currentState == CurrentState.Chase || brain.currentState == CurrentState.Engage || brain.currentState == CurrentState.Investigate) &&
    191.                   (brain.eyes.canSeeEnemy == true || brain.ears.canHearEnemy == true)  )
    192.                 {
    193.                     //see if the angle is too large when we're already wielding
    194.                     if(Vector3.Angle( aimTargetPos - Vector3.Lerp(defaultWeaponHoldingLocation.position, engageWeaponHoldingLocation.position, engageFactor), transform.forward) < maxWeaponAngle)
    195.                     {
    196.                         engageTarget = 1f;
    197.                     }
    198.                     else
    199.                     {
    200.                         engageTarget = 0f;
    201.                     }
    202.                 }
    203.                 else
    204.                 {
    205.                     engageTarget = 0f;
    206.                 }
    207.                
    208.                 //apply engage factor
    209.                 engageFactor = SmoothDampSnap(engageFactor, engageTarget, ref engageVel, engageTime, 0.01f);
    210.                
    211.  
    212.                 // Translate/rotate the weapon
    213.                 if( brain.healthManager.healthState == HealthState.Normal)
    214.                 {
    215.                
    216.                     Vector3 pos = Vector3.Lerp(defaultWeaponHoldingLocation.position, engageWeaponHoldingLocation.position, engageFactor);
    217.                     Quaternion rot = Quaternion.Lerp(defaultWeaponHoldingLocation.rotation, Quaternion.LookRotation(aimTargetPos - pos), engageFactor);
    218.  
    219.                     // Arbitrary holding location can be set by an external script for any purpose, such as positioning the weapon to a hand for melee attacks
    220.                     arbitraryFactor = SmoothDampSnap(arbitraryFactor, arbitraryHoldingLocation != null? 1f: 0f, ref arbitraryVel, engageTime, 0.01f);
    221.  
    222.                     if (arbitraryHoldingLocation != null) lastArbitraryHoldingLocation = arbitraryHoldingLocation;
    223.  
    224.                     if (lastArbitraryHoldingLocation != null) {
    225.                         pos = Vector3.Lerp(pos, lastArbitraryHoldingLocation.position, arbitraryFactor);
    226.                         rot = Quaternion.Lerp(rot, lastArbitraryHoldingLocation.rotation, arbitraryFactor);
    227.                     }
    228.  
    229.                     currentHoldingWeapon.position = pos;
    230.                     currentHoldingWeapon.rotation = recoilOffset * rot;
    231.                 }
    232.  
    233.                 // Fade out the recoil offset
    234.                 recoilOffset = Quaternion.Lerp(recoilOffset, Quaternion.identity, Time.deltaTime * 3f);
    235.  
    236.                 if(currentHoldingWeapon.GetComponent<GatewayGamesWeapon>() != null)
    237.                 {
    238.                     //set being held and fire type, if info is given
    239.                     currentWeaponFiretype = currentHoldingWeapon.GetComponent<GatewayGamesWeapon>().weaponType;
    240.                     meleeAttackDistance = currentHoldingWeapon.GetComponent<GatewayGamesWeapon>().meleeAttackDistance;
    241.                     currentWeaponIK = currentHoldingWeapon.GetComponent<GatewayGamesWeapon>().ikType;
    242.                     currentIKTargets.leftHandTarget = currentHoldingWeapon.GetComponent<GatewayGamesWeapon>().ikLeftHand;
    243.                     currentIKTargets.rightHandTarget = currentHoldingWeapon.GetComponent<GatewayGamesWeapon>().ikRightHand;
    244.  
    245.                     //apply dropping/picking back up based on health e.g. knocked down
    246.                     if( brain.healthManager.healthState != HealthState.Normal)
    247.                     {
    248.                         if( currentHoldingWeapon.rigidbody == null )
    249.                         {
    250.                             currentHoldingWeapon.GetComponent<GatewayGamesWeapon>().Drop();
    251.                         }
    252.                     }
    253.                     else
    254.                     {
    255.                         if( currentHoldingWeapon.rigidbody != null )
    256.                         {
    257.                             currentHoldingWeapon.GetComponent<GatewayGamesWeapon>().BePickedUp( transform );
    258.                            
    259.                         }
    260.                     }
    261.                    
    262.                    
    263.                 }
    264.                 else
    265.                 {
    266.                     //default back to ranged weapon if nothing specified
    267.                     currentWeaponFiretype = FireType.Ranged;
    268.                     currentWeaponIK = IKTypes.BothHands;
    269.                 }
    270.                
    271.                
    272.                
    273.             }
    274.             else
    275.             {
    276.                 //reset vars
    277.                 currentWeaponIK = IKTypes.NoHands;
    278.                 currentIKTargets.leftHandTarget = null;
    279.                 currentIKTargets.rightHandTarget = null;
    280.             }
    281.            
    282.             //smooth out aiming
    283.             aimTargetPos = Vector3.Lerp( aimTargetPos, aimTempPos, 8f * Time.fixedDeltaTime );
    284.  
    285.  
    286.            
    287.         }
    288.        
    289.        
    290.        
    291.        
    292.        
    293.         /// <summary>
    294.         /// Changes the weapon to the specified one.
    295.         /// </summary>
    296.         /// <param name="newWeapon">New weapon.</param>
    297.         public virtual void ChangeWeapon(Transform newWeapon)
    298.         {
    299.             //cycle and find the right one
    300.             for(int x = 0; x < multipleWeapons.Count; x++)
    301.             {
    302.                 if(multipleWeapons[x].weaponObject == newWeapon)
    303.                 {
    304.                     ChangeWeapon( x);
    305.                     break;
    306.                 }
    307.             }
    308.            
    309.         }
    310.        
    311.        
    312.        
    313.        
    314.        
    315.         /// <summary>
    316.         /// Fires/throws the secondary weapon.
    317.         /// </summary>
    318.         public virtual void FireSecondaryWeapon()
    319.         {
    320.             //check null reference
    321.             if(secondaryWeaponData.secondaryWeaponPrefab == null)
    322.             {
    323.                 return;
    324.             }
    325.            
    326.             //check if we have enough ammo
    327.             if(secondaryWeaponData.secondaryWeaponAmount > 0)
    328.             {
    329.                 //create the weapon to throw
    330.                 Rigidbody newSecondaryWeapon = Instantiate( secondaryWeaponData.secondaryWeaponPrefab, defaultWeaponHoldingLocation.position,
    331.                                                        Quaternion.Euler( defaultWeaponHoldingLocation.forward ) ) as Rigidbody;
    332.                
    333.                 //apply the correct force
    334.                 newSecondaryWeapon.AddRelativeForce( secondaryWeaponData.throwVector * secondaryWeaponData.throwForce );
    335.                
    336.                 //apply new data
    337.                 secondaryWeaponData.secondaryWeaponAmount -= 1;
    338.                 secondaryWeaponData.lastThrowTime = Time.time;
    339.                
    340.                 //set the animation
    341.                 brain.modelManager.ApplySecondaryWeaponAnimation();
    342.                
    343.             }
    344.            
    345.         }
    346.        
    347.        
    348.        
    349.        
    350.         /// <summary>
    351.         /// Changes the weapon to the specified one's index.
    352.         /// </summary>
    353.         /// <param name="newWeapon">New weapon.</param>
    354.         public virtual void ChangeWeapon(int newWeapon)
    355.         {
    356.             //deactivate the old weapon
    357.             currentHoldingWeapon.gameObject.SetActive( false);
    358.            
    359.             //activate the new weapon
    360.             currentHoldingWeapon = multipleWeapons[newWeapon].weaponObject;
    361.             currentHoldingWeapon.gameObject.SetActive( true);
    362.            
    363.         }
    364.        
    365.        
    366.         /// <summary>
    367.         /// Fires the current weapon.
    368.         /// </summary>
    369.         public virtual void Fire()
    370.         {
    371.             //call the main function, but with default values
    372.             Fire ( currentWeaponFiretype );
    373.  
    374.         }
    375.                        
    376.        
    377.         /// <summary>
    378.         /// Fires the weapon.
    379.         /// </summary>
    380.         /// <param name="fireType">Fire type.</param>
    381.         public virtual void Fire( FireType fireType )
    382.         {
    383.             //check if we're holding the weapon in normal mode, and thus might shoot ourselves :D
    384.             if(engageFactor < 0.7f)
    385.             {
    386.                 return;
    387.             }
    388.            
    389.             //send a message to the weapon with the way we're firing it
    390.             //currentHoldingWeapon.SendMessage( "Fire", SendMessageOptions.DontRequireReceiver );
    391.             if (currentHoldingWeapon.GetComponent<GatewayGamesWeapon>().Fire()) {
    392.                 var w = currentHoldingWeapon.GetComponent<GatewayGamesWeapon>();
    393.                 recoilOffset = Quaternion.AngleAxis(w.recoilAmount * (1f + Random.value * 0.3f), w.recoilVector);
    394.             }
    395.  
    396.             //make the animation play if needed
    397.             if(fireType == FireType.Melee)
    398.             {
    399.                 brain.modelManager.ApplyMeleeAnimation();
    400.             }
    401.            
    402.             //debug if needed
    403.             if(debug)
    404.             {
    405.                 Debug.Log( "SAI: Requesting bullet firing; " + Time.time );
    406.             }
    407.            
    408.         }
    409.        
    410.        
    411.        
    412.         /// <summary>
    413.         /// Aims at specified position.
    414.         /// </summary>
    415.         /// <param name="target">Target.</param>
    416.         public virtual void AimAtPosition(Vector3 target)
    417.         {
    418.             //set the new target
    419.             aimTempPos = target;
    420.            
    421.         }
    422.        
    423.        
    424.         /// <summary>
    425.         /// Turns aiming off.
    426.         /// </summary>
    427.         public virtual void TurnOffAiming()
    428.         {
    429.             //set new target to zero to signify that we don't need to aim any more
    430.             aimTargetPos = Vector3.zero;
    431.         }
    432.        
    433.        
    434.        
    435.         /// <summary>
    436.         /// Reloads the weapon.
    437.         /// </summary>
    438.         public virtual void ReloadWeapon()
    439.         {
    440.            
    441.             currentHoldingWeapon.SendMessage( "Reload", SendMessageOptions.DontRequireReceiver );
    442.         }
    443.        
    444.        
    445.        
    446.         /// <summary>
    447.         /// Determines whether the weapon can see the enemy.
    448.         /// </summary>
    449.         /// <returns><c>true</c> if this instance can see enemy from the weapon; otherwise, <c>false</c>.</returns>
    450.         public virtual bool CanSeeEnemyFromWeapon()
    451.         {
    452.             //set some variables
    453.             bool result = false;
    454.            
    455.            
    456.             if(currentHoldingWeapon != null)
    457.             {
    458.                 //raycast
    459.                 if( Physics.Raycast( currentHoldingWeapon.position, ( brain.currentEnemy.transform.position + new Vector3(0, 0.1f, 0) - currentHoldingWeapon.position ).normalized, out weaponSeeEnemyData,
    460.                                    ( brain.currentEnemy.transform.position + new Vector3(0, 0.1f, 0) - currentHoldingWeapon.position ).magnitude ) )
    461.                 {
    462.                     //before, resulting in a negative result, check whether the hit data is the enemy
    463.                     if( brain.ObjectAtLocation( brain.currentEnemy.transform, weaponSeeEnemyData.point ) == true )
    464.                     {
    465.                         result = true;
    466.                     }
    467.                    
    468.                 }
    469.                 else
    470.                 {
    471.                     //if theres nothing, report that its visible
    472.                     result = true;
    473.                 }
    474.                
    475.                
    476.             }
    477.            
    478.            
    479.             return result;
    480.         }
    481.        
    482.        
    483.         /// <summary>
    484.         /// Sends a message to the brain, saying that the AI needs to reload its weapon.
    485.         /// </summary>
    486.         public void WeaponNeedsReloading()
    487.         {
    488.             brain.ReloadWeapon();
    489.         }
    490.        
    491.        
    492.         /// <summary>
    493.         /// Call this function if you need to simulate the
    494.         /// </summary>
    495.         /// <param name="posOfBullet">Position of bullet.</param>
    496.         public void BulletFired(Vector3 posOfBullet)
    497.         {
    498.             brain.ears.BulletFired( posOfBullet);
    499.         }
    500.     }
    501.    
    502.    
    503. }
    504.  
    505.  
    506.  
     
    Last edited: Nov 11, 2014
  33. 99thmonkey

    99thmonkey

    Joined:
    Aug 10, 2012
    Posts:
    525
    Integrate well with realistic fps?
     
  34. uvavoo

    uvavoo

    Joined:
    Oct 15, 2007
    Posts:
    60
    nikita. I have done a quick test with the new code and it seems to have solved the problem !! I will continue testing. well done. Recommend other people with this problem try it as well.

    Cover system. Ok managed to set up some predefined positions (forgot to APPLY to the prefab, thats why they were disappearing, doh!).
    But still the enemy, no matter how much he is damaged does not seek cover.
    Have tried playing with the emotion data, but no difference. He is a very brave soldier and stands in position.

    I think this product has lots of potential, It would be nice, for example, if when the players gunsight was trained on the enemy, the enemy would either duck, move or seek cover. If he was shot, even once, he would change position or crouch or find cover etc. Just suggestions.
     
    nikita68 likes this.
  35. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @99thmonkey -
    Heres the tutorial:


    @uvavoo -

    1) Hallelujah! That took a long time to fix :D
    2) I'll look into cover behaviour, but we're actually going to be making some big changes in the next few weeks, due to a coming deal with a new cover system developed by a 3rd party.

    Please give me as much suggestions as you can! It always helps us to improve our asset.
     
    hopeful likes this.
  36. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    @nikita68 Quick question... have you guys looked into Fuzzy AI... another package just introduced it and I was wondering what your feeling where about it...
     
  37. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @Licarell - From what i gather, that AI is basically only for UFE, and doesn't really apply to ranged based AIs.
     
  38. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    Ah... well from what I read from them was that they where using Fuzzy AI concepts to build their AI... and I never heard of it and googled it and ran across a lot of research like this:

    http://homes.di.unimi.it/~pirovano/pdf/fuzzy_ai_in_games.pdf

    So I was just wondering what you all thought of it...
     
  39. uvavoo

    uvavoo

    Joined:
    Oct 15, 2007
    Posts:
    60
    "2) I'll look into cover behaviour, but we're actually going to be making some big changes in the next few weeks, due to a coming deal with a new cover system developed by a 3rd party."

    Good news. I can't seem to get the current system working correctly, or at least as I want it to work. Been looking at the emotion data. When the enemy is being shot, his fear goes up, but not by much, and quickly goes down. Perhaps he should be more afraid and stay afraid longer. Maybe this will invoke cover seeking behaviour more often? Also on the flight or fight variable, is zero more likely to flee and 1 more likely to fight, or the other way around?
    In general I like this emotion thing, as when placing two identical enemies, they behave differently to one another, and also when the game is reloaded, behave differently. I suppose this is the fuzzy logic that the previous poster is referring to.
    My suggestions.
    1. "Is the enemy targeted". If the player has its sights on the enemy this should affect enemy behaviour, either, a) the enemy should stay in cover, b) the enemy should seek cover c) crouch. etc. Perhaps in this case Fear could be increased.
    2. "Is the enemy being shot at". If the enemy is hit. Similar behaviour to 1, above.
    3. As suggested before. "minimum distance of enemy to player". A variable, which for example if 10 will not allow enemy to come closer than 10 metres. If the enemy is capable of a melee attack, then this value will remain at default 0.
    4. "Idle" state. Possibility of enemy just being stood idle (smoking a fag or another animation) in a relaxed state. Possibly his senses reduced when in this state.
    5. I like the idea of "Can call to others". Perhaps these enemies should remain in the patrol or idle state until called. This would make for some good game play. (I assume this works by enemy tags?).
    6. Make fully functional enemy prefabs which you can drop into your game (sell them separately on asset store). Soldiers, zombies, monsters, sci-fi baddies with laser guns etc.

    The above are just suggestions and are not meant as criticism. But i feel that they would be relatively easy to implement into your current structure and would, I think improve the apparent intelligence of the enemy.

    Finally I have continued to test out the problem with the gun through body code and the problem has not re-occurred so far. Keep up the good work, and I look forward to the new cover system. Again, I would be happy to test out any new features, implementations of your asset.
     
    nikita68, Mayureshete and eridani like this.
  40. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    This is crucial for a realistic ranged character. Why would an enemy wielding a loaded assault rifle try to run right up to the player? Makes no sense in real life and in a game.
     
    Mayureshete likes this.
  41. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @Licarell - Very interesting read! Its more of a library of methods to make AI programming easier than actual AI package.

    @uvavoo -

    1) We will need to look into this, but this is really hard to implement, due to the different solutions that people are using (RFPS, UFPS, AI vs AI etc..).

    2) Thats actually in, but i'll probably make the behaviour more visible.

    3) + @eridani Just added this into 2.0.1 :D

    4) Thats just the patrol state, but a good idea with an extra animation slot!

    5) Yep, uses tags and range to determine the AIs to be called. Basically, you can do exactly that by deactivating "Automatically Search for new enemies" in the brain.

    6) Great idea! We've already got a soldier in, and we're working on a zombie model right now.

    I really enjoy implementing any suggestions we get. The more you post, the better the product will be and the longer it will live.
     
    eridani likes this.
  42. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    I'm curious, I have the asset but I have not cracked it open yet... can I build AI presets and then store them so I can (reuse) drag and drop the AI characteristics per character?

    Also I went to your website and tried to watch the videos and they are all set to private...
     
    Last edited: Nov 13, 2014
  43. eliteslayer

    eliteslayer

    Joined:
    May 12, 2013
    Posts:
    64
    For future updates would it be possible to add hit reactions once more, also a big one blood prefabs for when AI is hit and sounds for flesh hit to make the AI more realistic. And then as well as AI grenade throwing when behind cover or if player is behind cover to add more features. And i have one question... is it possible for the AI to have random wandering around the map to make it more dynamic like Cod bots and have it learn if it can respawn? i tried with Astar but found it kinda hard and not exactly what i was looking for because the AI would stand still until he sees the player then wander around where you were last or move a couple steps and stay still.
     
  44. 99thmonkey

    99thmonkey

    Joined:
    Aug 10, 2012
    Posts:
    525
    Why not just expose the "Damage" as a string and call it public string DamageMethodName="Damage"; then it can easily be changed in the inspector to whatever the developer wants.
     
    uvavoo likes this.
  45. 99thmonkey

    99thmonkey

    Joined:
    Aug 10, 2012
    Posts:
    525
    Does climbing ladders and jumping gaps work?
     
  46. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @EVERYBODY!

    Just sent out the first update in the 2.X cycle! Heres the feature list:

    2.0.1

    - Spawn manager
    - Clean up manager
    - Improved readability on some scripts
    - Added automatic weapon switching and weapon tactics based on range
    - Better ragdolls
    - Improved cover results
    - Added UFPS -> AI character converter
    - Wander function
    - If AI is too close to enemy, it automatically finds a new fighting position
    - Added property to change damage method name

    A special thank you goes out to everyone who helped us fight the bugs!

    @Licarell -
    Thats not implemented yet, but usually you only need to adjust one or two values.

    @eliteslayer -
    Hit reactions: already implemented
    Blood prefabs: noted for future update
    Grenade: already implemented; look into "Seconday Weapon" in the Gateway Games Weapon Manager

    Yep, we're adding wandering in 2.0.1 :)

    @99thmonkey -
    1) Just added that option. :)
    2) Jumping works, but climbing ladders depends on how you setup your navigation.
     
    Last edited: Nov 16, 2014
  47. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    Ah ok... Well I was wanting to build presets like zombie, hand weapons (fist, knives, glubs), range weapons ( archer, guns, sniper), when it came for the type of game I wouild call up the preset then drop it on my character.
     
  48. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289
    @Licarell - I'd just use prefabs, as that would include model, IK etc.. data.
     
  49. uvavoo

    uvavoo

    Joined:
    Oct 15, 2007
    Posts:
    60
    Nikita is there a possibility of access to 2.0.1 for testing purposes?
     
  50. nikita68

    nikita68

    Joined:
    Feb 8, 2013
    Posts:
    289