Search Unity

Third person cover controller

Discussion in 'Assets and Asset Store' started by EduardasFunka, May 23, 2017.

  1. EduardasFunka

    EduardasFunka

    Joined:
    Oct 23, 2012
    Posts:
    460
    Thanks tested 1 and 2 can confirm those are new bugs its priority now to fix it.

    3 we removed shot from sides on a low cover for a player. Before when you in low cover and at the end of cover you can only shoot at certain angles. It was bad game design because if angles do match you press shoot but character ignores you game looks broken. So we decided to do that character steps away from cover and shoots. we could not figure out how to do that in low covers and it still looks and feels good. Also, this feature to step away from tall cover and shoot probably took 2 months trial and error. Division probably the only cover shooter to do it right and they have tons of animations.

    we plan to do a big controller upgrade after AI. I made lots of new animations maybe we will go back to this but no promises yet as its very difficult feature to make it right.
     
    Last edited: Nov 9, 2018
  2. Toby31

    Toby31

    Joined:
    Jul 7, 2014
    Posts:
    37
    Thanks for the response and testing it out, didn't want to bother you coz I know you must be rushed of your feet.

    Had a feeling you might have had issues with the side step animation, which is a shame coz it did look cool.

    Look forward to the updates and really enjoying using the controller. :)
     
  3. rrabassa

    rrabassa

    Joined:
    Jul 17, 2013
    Posts:
    170


    Can't wait for the updates!

    Any suggestions for walking on a spherical terrain?

    -rich
     
  4. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    284
    HOW DO YOU CONSISTENTLY SETUP COVER?!?! I'm getting really ticked off with all these rotations, scaling, etc. I've done it 3 times and that's it. Each a different way and can't remember how. Ridiculous system.

    Apologies for the frustration. Please, some advice.
     
    Last edited: Nov 9, 2018
  5. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    237
    Its not so bad. The key is the mesh in the cover objects. He uses a cube. And the cover system work proportional to the scale that that's set too. Try just copying the cover nodes from the demo scene and placing them around. Don't parent them to the object your using as cover. I learned this pretty quickly.

    I recommend creating a cover object that include ONLY cover so you never need to worry about cover being scaled incorrectly - Unless its a moving object that is...

    I agree, its not immediately obvious how the cover portion of this asset even works. but that seems to work for me.
     
  6. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    284
    Thanks. I'll give it a go.
     
  7. Alexey1B

    Alexey1B

    Joined:
    May 15, 2017
    Posts:
    26
    Hello, i trying to temporary allow pass through terraine collider (for things like tunnel) but Physics.IgnoreCollision(characterCapsuleCollider, terraineCollider) not working, is exists some checks inside CharacterMotor what can produce this?
     
  8. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    237
    I'm trying the exact same thing. There's to parts to this gravity on the characters rigid. Ody is set to off...and also something in character motor that prevents them from falling thru. I have not yet found it either
     
  9. Alexey1B

    Alexey1B

    Joined:
    May 15, 2017
    Posts:
    26
    Partially solved, i add in my ThirdPersonInput bool to skip check movement in motor function IsFreeToMove: skipCheckMove || _motor.IsFreeToMove (for all 4 call). And triggering it near tunnel entrance , then dissable child colliders of character if exists before call Physics.IgnoreCollision. But still have a bit freezing when crossing terrain collider.
     
  10. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    237
    How are the layers being assigned to portions of the character?
    I was a making a minimap that is using masking. Part of that process requires me put my objects on a minimap layer. For them to move with the character its assigned too i need to set them as a child object. But when I start the scene they are not visible on my render texture. 1st thing I did was check the layer...sure enough they got re-assigned to the Character layer... how is this happening? and how to get around it?
     
  11. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    284
    I saw that too. Check his LayerManager.cs
     
    Paul-Swanson likes this.
  12. Pollawat

    Pollawat

    Joined:
    Aug 27, 2016
    Posts:
    156
    Hello sir.

    I notice that when the character moves the crosshair will get bigger. I found the one that controls the gun itself but not the character movement. where can I control this value, sir?

    - I understand that you use a sprite to display a crosshair and I love it. But I don't need the sprite to scale up that much when a character moves, it looks bad for me.
    - Where can I find that value to reduce the sprite scaling while character moves.
     
    Last edited: Nov 13, 2018
  13. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    237
    Well I finally figure this out

    So for the last 3 weeks, iv been struggling to get this to work:
    upload_2018-11-12_17-28-26.png

    So whats that's displaying is Weapon Name + Fraction of Bullets left till empty MAG | Total Bullet left for this weapon
    Code (CSharp):
    1. _text.text = gun.Name + " " + gun.LoadedBulletsLeft.ToString() +"/"+ gun.gunTypeMagSize.ToString() + " | " +gun.gunTypeBulletInventory.ToString();
    Initially I tried this:
    Code (CSharp):
    1. _text.text = gun.Name + " " + gun.LoadedBulletsLeft.ToString() + "/" + gun.MagazineSize.ToString() + " " + gun.BulletInventory.ToString();
    This didnt work because GunAmmo.cs is inheriting all its public variables from BaseGun.cs
    From my point of view it is NOT obvious that you cannot just set a public variable there and expect it to work...
    So for those of you that do not know how this works...as follows:

    Gun : BaseGun <- This essientially means if you want a value in Gun then set it up as a thingy in BaseGun first.

    So in the end, I had to add these 2 thing to BaseGun.cs:
    Code (CSharp):
    1. public abstract int gunTypeMagSize { get; }
    2. public abstract int gunTypeBulletInventory { get; }
    Then in Gun.cs:
    Code (CSharp):
    1. public override int gunTypeBulletInventory { get { return BulletInventory; }}
    2. public override int gunTypeMagSize { get { return MagazineSize; } }
    Then FINALLY in the gui portion:
    Code (CSharp):
    1.  _text.text = gun.Name + " " + gun.LoadedBulletsLeft.ToString() +"/"+ gun.gunTypeMagSize.ToString() + " | " +gun.gunTypeBulletInventory.ToString();
    So yea, in the end this took me like 3 weeks to get right...because there a some massive gaps in what I need to know to be a successful programmer...and I get that need to learn...I'm just irritated that no one answered my calls for help :( If you needed this knowledge here you go, now you know how that works, if not...just ignore my venting. Iv got a bit of a headache...happy I solved it...just tired now.

    Also if I'm wrong please let me know, all Iv had to learn by are Unity's wildly impractical and poorly explained codeing tutorials and youtube -- many of whom are not much better...
     
    Last edited: Nov 12, 2018
    WInDArt, Toby31, JBR-games and 2 others like this.
  14. HasnainKhan

    HasnainKhan

    Joined:
    Nov 8, 2016
    Posts:
    11
    Hello,
    I just bought this kit and I am wondering If I can add RPG and Grenade Launcher. I am working on adding these two weapons from last two weeks. But I can't get it working. Adding a new layer in animator for RPG and Grenade Launcher is not working. Any help will be appreciated. Thanks
     
    Last edited: Nov 13, 2018
  15. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    237
    Ok, since iv finally gotten the UI straightened out. I going to just share what iv got here now to see if I'v got the right idea...or if someone else already had something that works.
    I want to enter a collider on a drop I create to add ammunition to the selected weapon type.

    This is my best effort so far:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using CoverShooter;
    6.  
    7. public class AmmoDrop : MonoBehaviour
    8. {
    9.     /// <summary>
    10.     /// referance for the the script to send too
    11.     /// </summary>
    12.     public GameObject Player;
    13.     public CharacterMotor Motor;
    14.     public string PlayerTag = "Player";
    15.  
    16.     /// <summary>
    17.     /// Amount of Ammo you want to have picked up
    18.     /// </summary>
    19.     [Tooltip("Ammo you want sent to the inventory")]
    20.     public int AmmoDropAmount;
    21.     public int test;
    22.  
    23.     /// <summary>
    24.     /// Animations and related assets to be used with this weapon.
    25.     /// </summary>
    26.     [Tooltip("Animations and related assets to be used with this weapon.")]
    27.     public WeaponType Type;
    28.  
    29.     /// <summary>
    30.     /// Name of the gun ammo to be display on the HUD.
    31.     /// </summary>
    32.     [Tooltip("Name of the gun to be display on the HUD.")]
    33.     public string Name = "Ammo";
    34.  
    35.     // Use this for initialization
    36.     void Start ()
    37.     {
    38.         Debug.Log(Type+" is whats selected");
    39.      
    40.     }
    41.    
    42.     void OnTriggerEnter(Collider other)
    43.     {
    44.         if (other.gameObject.tag == PlayerTag)
    45.         {
    46.             /*
    47.             For the selected Type add AmmoDropAmount to Gun.BulletInventory
    48.             Display string Name Ammo Text then fade out over 3 seconds.
    49.             */
    50.         }
    51.     }
    52.  
    53. }
    54.  
    Now obviously this doesn't do jack right now except tell me its going to actually use the selected enum...and check it against the PlayerTag variable. What I do not know is how to actually add to the BulletInventory since it creates a new variable in that script itself...and not in BaseGun.cs -- And since gun is all inherited from BaseGun.cs I'm totally lost.
    Frankly I don't want to spend another 3 weeks trying to figure THIS part out too -- Id rather move on to other parts. So Does anyone have a already working solution?
     
  16. HasnainKhan

    HasnainKhan

    Joined:
    Nov 8, 2016
    Posts:
    11
    I am using CharacterMotor only for main player. And If I place CharacterMotor on all other characters game become so laggy so I wrote a script which take all zombie from a sphere and take nearest zombie and assign it to the MobileController in order to lock the aim. It's working but not that accurate. Here is my Code.
    Code (CSharp):
    1. public CoverShooter.MobileController mobileController;
    2.     GameObject nearestEnemy = null;
    3.     int maxDistance = 10;
    4.     float FoundNearestDistance = 1000;
    5.     private FieldOfView FOV;
    6.     public List<Transform> EnemiesInRange = new List<Transform>();
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.         FOV = GetComponent<FieldOfView> ();
    11.     }
    12.  
    13. IEnumerator MachineGunAI(){
    14.         while (true) {
    15.             yield return new WaitForSeconds (0.5f);
    16.             EnemiesInRange = FOV.visibleTargets;
    17.             foreach (Transform zombie in EnemiesInRange) {
    18.                 float Distance = Vector3.Distance (transform.position, transform.position);
    19.                 if (Distance < FoundNearestDistance) {
    20.                     FoundNearestDistance = Distance;
    21.                     nearestEnemy = zombie.gameObject;
    22.                 }
    23.             }
    24.             mobileController.Zombie = nearestEnemy.gameObject;
    25.         }
    26.     }
    Code (CSharp):
    1. void FindVisibleTargets() {
    2.         visibleTargets.Clear ();
    3.         Collider[] targetsInViewRadius = Physics.OverlapSphere (transform.position, viewRadius, targetMask);
    4.  
    5.         for (int i = 0; i < targetsInViewRadius.Length; i++) {
    6.             Transform target = targetsInViewRadius [i].transform;
    7.             Vector3 dirToTarget = (target.position - transform.position).normalized;
    8.             if (Vector3.Angle (transform.forward, dirToTarget) < viewAngle / 2) {
    9.                 float dstToTarget = Vector3.Distance (transform.position, target.position);
    10.  
    11.                 if (!Physics.Raycast (transform.position, dirToTarget, dstToTarget, obstacleMask) && target.GetComponent<CoverShooter.CharacterHealth>().Health > 0) {
    12.                     visibleTargets.Add (target);
    13.                 }
    14.             }
    15.         }
    16.     }
    17.  
    18.  
    19.     public Vector3 DirFromAngle(float angleInDegrees, bool angleIsGlobal) {
    20.         if (!angleIsGlobal) {
    21.             angleInDegrees += transform.eulerAngles.y;
    22.         }
    23.         return new Vector3(Mathf.Sin(angleInDegrees * Mathf.Deg2Rad),0,Mathf.Cos(angleInDegrees * Mathf.Deg2Rad));
    24.     }
     
    MLipscomb likes this.
  17. HasnainKhan

    HasnainKhan

    Joined:
    Nov 8, 2016
    Posts:
    11
    Yeah I spent a week to figure it out. And I got it working. Here is my code.
    Code (CSharp):
    1. private void OnTriggerEnter(Collider other)
    2.     {
    3.         if (other.tag == "Player" && other.GetComponent<CoverShooter.CharacterMotor>().EquippedWeapon.Gun != null) {
    4.             other.GetComponent<CoverShooter.CharacterMotor>().EquippedWeapon.Gun.GetComponent<CoverShooter.Gun>().BulletInventory += 60;
    5.  
    6.             Destroy (gameObject);
    7.         }
    8.         if (other.tag == "Player" && other.gameObject.layer == 14 && other.GetComponent<CoverShooter.CharacterMotor>().EquippedWeapon.Gun == null) {
    9.             other.GetComponent<CoverShooter.CharacterInventory> ().Weapons [1].RightItem.GetComponent<CoverShooter.Gun> ().BulletInventory += 60;
    10.  
    11.             Destroy (gameObject);
    12.         }
    13.     }
     
    satchell and Paul-Swanson like this.
  18. HasnainKhan

    HasnainKhan

    Joined:
    Nov 8, 2016
    Posts:
    11
    First Condition will be executed if Player have gun then ammo will be added to current active gun and second condition will be executed if player don't have gun then ammo will be added to gun which is placed at index 1.
     
    Toby31 and Paul-Swanson like this.
  19. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    237
    That worked perfectly I'll Reply with my version once I get it perfect. Problably tonight TBH.
    Just expanding it a bit **

    Here is my version, I simply combine my skeleton code from yesterday with yours (it now had a pop up and plays a sound):

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using CoverShooter;
    7.  
    8. [RequireComponent(typeof(AudioSource))]
    9. [RequireComponent(typeof(Rigidbody))]
    10.  
    11. public class AmmoDrop : MonoBehaviour
    12. {
    13.     /// <summary>
    14.     /// Select the weaponType you want to add ammo for
    15.     /// </summary>
    16.     public enum AmmoType { Pistol, Rifle, Shotgun, Sniper }
    17.  
    18.     [Tooltip("Select the Type of Ammo you want to restock")]
    19.     public AmmoType refNumber;
    20.     private int AmmoSelector;
    21.  
    22.     /// <summary>
    23.     /// referance for the the script to send too
    24.     /// </summary>
    25.     [Tooltip("Player Object Goes here")]
    26.     public GameObject Player;
    27.  
    28.     public CharacterMotor Motor;
    29.     private string PlayerTag;
    30.  
    31.     /// <summary>
    32.     /// Amount of Ammo you want to have picked up
    33.     /// </summary>
    34.     [Tooltip("Ammo you want sent")]
    35.     public int AmmoDropAmount = 5;
    36.  
    37.     public GameObject FloatingTextPrefab;
    38.  
    39.  
    40.     /// <summary>
    41.     /// Name of the gun to be display on the HUD.
    42.     /// </summary>
    43.     [Tooltip("Popup you want for the HUD")]
    44.     private string GUIpopup;
    45.  
    46.     public AudioClip soundEffect;
    47.     AudioSource audio;
    48.     private int SoundCount = 0;
    49.  
    50.  
    51.     // Use this for initialization
    52.     void Start()
    53.     {
    54.         PlayerTag = Player.tag;
    55.         AmmoSelector = (int)refNumber;
    56.         audio = GetComponent<AudioSource>();
    57.         //Debug.Log(PlayerTag + " is the players assigned tag");
    58.         //Debug.Log(refNumber + " is whats selected, its index is "+AmmoSelector);
    59.         //Debug.Log(AmmoDropAmount+" is how much this is set too");
    60.     }
    61.  
    62.     void OnTriggerEnter(Collider other)
    63.     {
    64.  
    65.         if (other.tag == PlayerTag && other.gameObject.layer == 10) //&& other.GetComponent<CoverShooter.CharacterMotor>().EquippedWeapon.Gun != null)
    66.         {
    67.             other.GetComponent<CoverShooter.CharacterInventory>().Weapons[AmmoSelector].RightItem.GetComponent<CoverShooter.Gun>().BulletInventory += AmmoDropAmount;
    68.             /*
    69.             Display string Name Ammo Text then fade out over 3 seconds.
    70.             */
    71.             if (FloatingTextPrefab != null)
    72.             {
    73.                 SendGUItext();
    74.                 PlaySound();
    75.                 //           Debug.Log(GUIpopup);
    76.             }
    77.             Destroy(gameObject);
    78.         }
    79.  
    80.         /*
    81.         Display string Name Ammo Text then fade out over 3 seconds.
    82.         */
    83.  
    84.     }
    85.  
    86.     void SendGUItext()
    87.     {
    88.         GUIpopup = "+ " + AmmoDropAmount + " " + refNumber.ToString();
    89.         var go = Instantiate(FloatingTextPrefab, transform.position, Quaternion.identity);
    90.         go.GetComponent<TextMesh>().text = GUIpopup;
    91.    
    92.     }
    93.  
    94.     void PlaySound()
    95.     {
    96.         if (!audio.isPlaying && SoundCount < 1)
    97.         {
    98.             audio.PlayOneShot(soundEffect, 1.0F);
    99.             SoundCount++;
    100.         }
    101.         else return;
    102.     }
    103. }
    I also created a Text Mesh prefab and using this code kill the instantiate object after 3 seconds:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class FloatingText : MonoBehaviour
    6. {
    7.  
    8.     public float DestroyTime = 3f;
    9.     public Vector3 Offset = new Vector3(0, 1, 0);
    10.     // Use this for initialization
    11.     void Start()
    12.     {
    13.         Destroy(gameObject, DestroyTime);
    14.  
    15.         transform.localPosition += Offset;
    16.     }
    17.  
    18. }
    I have noticed after doing all this. the Shotgun Inventory appears to be broken. it never subtracts from the ammo count, and you can skip the chamber reloading simply by hold reload down. The video below is the system in action. Also shows the shotgun glitch...

     
    Last edited: Nov 15, 2018
  20. umair21

    umair21

    Joined:
    Mar 4, 2016
    Posts:
    85
    Hi there, I just created a terrain, normal unity terrain. Everything's working fine but when I stop my player on a slope, it starts sliding down slowly. Why is that so?
     
    Last edited: Nov 15, 2018
  21. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    284
    @Rahd and I just got done discussing this.

    https://forum.unity.com/threads/third-person-cover-controller.472313/page-26#post-3857491

    Basically, @EduardasFunka is doing all the proper work he needs to in order to check for slope but he's using a very important constant that he has not provided as a parameter. Read the thread. A simple adjustment to pull out the constant he's using so you can adjust it "should" work.
     
    Last edited: Nov 16, 2018
    umair21 likes this.
  22. Cell_Unity

    Cell_Unity

    Joined:
    Nov 13, 2018
    Posts:
    4
    Is there any method, where I can assign custom position for player, for auto move(like I want player move automatically to my specified position regardless of input from mouse or keyboard) (Third person cover shooter scene )
     
  23. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    229
    Try the strategy example it has that, all you have to do is change the player gameobject with a transform that follows the mouse clicks or something
     
    Last edited: Nov 16, 2018
    Paul-Swanson likes this.
  24. HasnainKhan

    HasnainKhan

    Joined:
    Nov 8, 2016
    Posts:
    11

    Last Light - Zombie Survival Developed By Gamerz Studio. This is just a trailer. We will release the game next week. Last Light is developed by using Third Person Cover Controller. I hope you will like it. :)
     
    Last edited: Nov 17, 2018
  25. CodemasterGames

    CodemasterGames

    Joined:
    Aug 11, 2014
    Posts:
    7
    Hey guys, I'm using TPCC. My character doesnt aim or fire when he is on slope and he is sliding down. I placed a plane. I dropped my character on it then i give a 5 x angle to plane. character sliding down again. What is wrong what do you think?
     
  26. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    237
    The sliding thing is known see back a few comments where a link is given on how to fix that. But not firing or aiming? Can you share a gif or video?
     
  27. CodemasterGames

    CodemasterGames

    Joined:
    Aug 11, 2014
    Posts:
    7
    I found the problem. I give slope friction physic material to terrain then all problems fixed
     
  28. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    229
    Yes , but as Paul-Swanson said it will cause problem, and it did for me (physics performance issue ) , try the script too .
     
    CodemasterGames likes this.
  29. bruneduardo1

    bruneduardo1

    Joined:
    Nov 18, 2018
    Posts:
    1
    Hi, I'm not sure if I still purchase the feature now, all the character controllers I've seen do not have an inventory system, can not we do a inventory pro or inventory master integration? Or you can also do your own inventory! If you want to make your own inventory I'll leave the link to a youtube channel that has good quality and is free.
    LINK :


    "THE FINAL A GAME WITHOUT INVENTORY IS NOT A GAME" \O-O/

    sorry for my English
     
    Last edited: Nov 18, 2018
    satchell, fnndo and Neviah like this.
  30. umair21

    umair21

    Joined:
    Mar 4, 2016
    Posts:
    85
    Thanks buddy. It worked. That line you mentioned "const float slopeThreshold" it was in a method. I just moved it out and made it global so that I could easily access it. Replaced const with public and it popped up in the inspector, Yeey. On value of 0 my character doesn't slide down anymore. :p
    You saved me. :D:D:D:):):)
     
    Rahd likes this.
  31. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    284
    NP. 0 might be a little too low. You won't slide down Mt. Everest with that setting :D. I have mine at 8 for a hilly terrain but again, it all depends on your terrain.
     
  32. dnaster

    dnaster

    Joined:
    Nov 18, 2013
    Posts:
    28
    do anyone know how to make the enemy character start shooting faster/attack the player with quickness?
    my enemy characters are passing the player and than shooting after. my player is set to 1 in the actor script.
    thanks in advance
     
  33. maxray

    maxray

    Joined:
    Aug 26, 2014
    Posts:
    26
    Hi, guys, I want to replace the built-in navmesh system with
    A* pathfinding project, could you add an integration script for it?
    I found the AIMovement script a little complicated.
     
  34. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,118
    I have updated my project to Unity 2018 last version and now the performance is much worse. I lost 12-15 fps in the main desert scene.:( I´m considering go back to 2017...

    Is that normal?
     
  35. rrabassa

    rrabassa

    Joined:
    Jul 17, 2013
    Posts:
    170
     
    redoxoder likes this.
  36. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    284
    I got a little frustrated with putting HitEffect.cs scripts on everything and wasn't really sure how to easily deal with water. So I created a script to attach to a weapon which will create hit effects based on which layer it hits, i.e - Terrain, Stone, Water, etc. Thought I'd share it.

    SerializedMonoBehaviour is from Odin. I used it for my own ease to deal with Dictionaries in the Inspector so if you don't have Odin you'll need to change it to MonoBehaviour.

    Sorry, this does require a change to the Hit structure and that is to add a
    public float Force
    variable.

    Code (CSharp):
    1.  
    2. public class HitLayerEffects : SerializedMonoBehaviour {
    3.  
    4.     /// <summary>
    5.     /// Effect to be instantiated on the point of bullet impact.
    6.     /// </summary>
    7.     [Tooltip("Name of the map layer and the hit particle to instance")]
    8.     public Dictionary<string, GameObject> BulletEffects;
    9.  
    10.     /// <summary>
    11.     /// Time to wait before destroying an instantiated effect object.
    12.     /// </summary>
    13.     [Tooltip("Time to wait before destroying an instantiated effect object.")]
    14.     public float DestroyAfter = 5;
    15.  
    16.     private Collider _collider;
    17.  
    18.     public void OnHit(int mask, Hit hit) {
    19.  
    20.         GameObject prefab = null;
    21.         if (BulletEffects.TryGetValue(LayerMask.LayerToName(mask), out prefab)) {
    22.             var effect = GameObject.Instantiate(prefab);
    23.             effect.transform.SetParent(null);
    24.             effect.transform.position = hit.Position + hit.Normal * 0.1f;
    25.             effect.SetActive(true);
    26.  
    27.             // This adds a force to your bullet shots
    28.             Rigidbody rb = hit.Target.GetComponent<Rigidbody>();
    29.             if (rb != null && hit.Force > 0f) {
    30.                 rb.AddForce(-hit.Normal * hit.Force, ForceMode.VelocityChange);
    31.             }
    32.             GameObject.Destroy(effect, 4);
    33.         }
    34.     }
    35.  
    36.     private void Awake() {
    37.         _collider = GetComponent<Collider>();
    38.     }
    39.  
    40.     private void OnValidate() {
    41.         DestroyAfter = Mathf.Max(0, DestroyAfter);
    42.     }
    43. }
    44.  
    Unfortunately, I didn't know how to map the Layers to its enumerated list, to create a drop down selectable menu. So you have to type in the layer name as a string.

    Enjoy.
     
    Last edited: Nov 23, 2018
    satchell and Rahd like this.
  37. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    237
    When you made this did you also add a Force variable in hit.cs? What you posted wont work for me keeps saying Force is not a Hit hit parameter. Easily figured out but was wondering...
     
  38. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    284
    Yeah - just realized that was only half the story.

    Perform the following steps:
    1. In the Hit.cs script add
    Code (CSharp):
    1. public float Force;
    2. In the BaseGun.cs script, reference the new script.
    Code (CSharp):
    1. private HitLayerEffects _hitLayers;
    3. In the Start() method add:
    Code (CSharp):
    1.  _hitLayers = GetComponent<HitLayerEffects>();
    4. Then, continuing in BaseGun.cs, look for the 2 or 3 instances where he sends OnHit:
    Code (CSharp):
    1. hit.collider.SendMessage("OnHit", hitStruct, SendMessageOptions.DontRequireReceiver);
    and add
    Code (CSharp):
    1. else if (_hitLayers != null)
    2.    _hitLayers.OnHit(hit.collider.gameObject.layer, hitStruct);
    after it. This will still give precedence to the HitEffect.cs scripts.

    I guess it's a little more involved but worth it. I did it this way, creating 2 OnHit function definitions instead of adding the layerMask to the Hit structure as well, so that you can still use HitEffects.cs and not mess up what's already in place.
     
    Last edited: Nov 23, 2018
    satchell and Rahd like this.
  39. gubwe

    gubwe

    Joined:
    Oct 20, 2017
    Posts:
    2
    Hie, how did you integrate it with playmaker? I tried but got a lot of errors
     
  40. fnndo

    fnndo

    Joined:
    May 10, 2016
    Posts:
    27
    Hi guys.
    Does anyone knows if this template plays well along UMA?
     
  41. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    229
    yeah layer are index based , use
    List<List<string>> layerNames = new List<List<string>>();

    // start from 8 since the first 8 are unity default layers and end at 32 since that's the limit
    for(int i=8;i<=31;i++)

    { var layerN=LayerMask.LayerToName(i);

    if(layerN.Length>0)

    layerNames.Add(layerN) }

    then add them to the enum using .Add i think ...
    great script i will use parts of it <3
     
    jnbbender likes this.
  42. maxray

    maxray

    Joined:
    Aug 26, 2014
    Posts:
    26
    Hi, guys, Do you have plan to add vehicle interaction, just like enter and exit and driver ik etc.
     
    xDeveloper likes this.
  43. rrabassa

    rrabassa

    Joined:
    Jul 17, 2013
    Posts:
    170
    Hello!

    How do I adjust the distance of the camera to the player?

    thanks,
    rich
     
  44. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    62
    Import the Standard Assets and Third Person Cover Shooter. Download the Enter Exit Vehicle Unity Package (from google drive) here.

    How To: Playlist
    Adding Mobile Controls Pt 1 & Pt 2

    ⚠⛔ On the ThirdPersonInput.cs at around 14:40 in PT 1 do not comment lines 476 - 486 and leave "* scale" in the camera.Horizontal and .Vertical. Thanks for pointing this out.
    Enter Exit Vehicle Pt 1 & Pt 2
    Minimap
     
    Last edited: Apr 28, 2019
    Lay84, SteveB and SwbZay like this.
  45. CodemasterGames

    CodemasterGames

    Joined:
    Aug 11, 2014
    Posts:
    7
    Hey satchell,

    I'm trying to change movement system. When i press s character turns %180 degrees and move towards. I wanna, when i press s character has to move backwards. How can i do that? I watched your video and you did this movement system
     
  46. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    62
    Try pushing "s" twice..
     
  47. redoxoder

    redoxoder

    Joined:
    May 11, 2013
    Posts:
    63
  48. Alexey1B

    Alexey1B

    Joined:
    May 15, 2017
    Posts:
    26
    Hello, at AiAim line 183 _hasWalkDirection = true. But then never change to false, this produce bad aiming of AI. For my case disable this line and change at motor gun.Allow(IsGunReady && !_isFalling && (!_cover.In || _coverAim.Step == AimStep.Aiming) && Vector3.Dot(vector, transform.forward) > to higther value (0.9) gave better precision of AI aiming.
    Could you look at situation with _hasWalkDirection and maybe change hardcoded 0.5 at .dot()> check to public field. Could you also change common fileds of BaseGun to protected level. And another one request) - please do something with reset renderers layer in motor: renderer.gameObject.layer = layer . What reason of it? I need setup different layers at gun
     
    JBR-games likes this.
  49. VENOMOUS09

    VENOMOUS09

    Joined:
    Dec 27, 2014
    Posts:
    37
    can you add xbox controller support ?
     
  50. satchell

    satchell

    Joined:
    Jul 2, 2014
    Posts:
    62
    @VENOMOUS09 if you take a look at the videos I posted it's using the CROSS platform input. Have you looked at the Sample assets provided from Unity in the Asset Store? The Input script I edited, I added in the functionality for PS4, XBOX, PC, Mobile....

    Keep in mind the Part 2 video, working with the weapon buttons those will need to be edited somehow to work either with a Pause screen or something convenient for consoles. I will continue to work on the Cross Platform... I have never published on XBOX or PS4. If you follow my videos just focus on the Input script don't worry about the Mobile UI obviously. Let me know if you do.
     
    Last edited: Nov 26, 2018
    SteveB likes this.