Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[UNITY 5 FPS Tutorials] GTGD S3 - Advanced First Person Shooter

Discussion in 'Community Learning & Teaching' started by GTGD, Oct 9, 2015.

  1. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I think you'll need to prepare a diagram or something because I don't understand what you are doing or trying to achieve
     
  2. NPBirader

    NPBirader

    Joined:
    Feb 23, 2015
    Posts:
    20
    I wanted to make a shooting anim for the npc.
    I added a new State to the animator and made a trigger for calling it. I added a new parameter string to the npc master and modified the npc animation script. In the npc_RangeWeaponstate script i made a if and a else if statement. if the bool i created in the statepattern called "hasShootingAnim" is true then call the animation and the gunmaster.npcinput.
    Else if its false then only gunmaster.npcinput.

    If i wanted that to work i must have a bool called "npcHasShootingAnim" in the gunmaster and check if its not true in the gun_Animator script to not call the gunshootinganim.
    I dont want this bool. I need to know how i can get the statepattern from the gun_Animator to acces the bool in the statepattern...
     
  3. Demondarem

    Demondarem

    Joined:
    Aug 31, 2016
    Posts:
    2
    i changed the weapon, when i shoot the grenades are going up
    how to fix this?
     
  4. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    No that doesn't sound like a correct way to be going about it. You should focus on using the Master script as the main bridge for communications. I still don't have a clear idea of what you are trying to do. For these sorts of things you should draw a diagram and it will make more sense to yourself. If you can't draw a diagram then you know automatically that it is not the right approach.
     
  5. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    use gravity on?
     
  6. Siliwinter

    Siliwinter

    Joined:
    Dec 6, 2015
    Posts:
    15
    Hi! i was on episode 106 after doing the script and setting the settings in the inspector i try to play the game but i can't reload.

    the R key is not working and finishing the ammo does not automatically reload either.

    I went over the script over 20 times but everything looks the same if you can help please do i am stuck.
     
    Last edited: Sep 2, 2016
  7. Mondspringer

    Mondspringer

    Joined:
    Jun 2, 2016
    Posts:
    4
    Thanks for all of those tutorials but i have a problem depressing me over a week i cant figure out how to fix.
    its about the Player inventory (Vid 54) that there is no cube showing up if deactivate them both at the Start of the test.
    Yes they both have the tag Item.
    And yes they are children of the Camera Gameobject of the FPSController
    And yes i Player has the Player_Inventory Script wich is filled out.
    so i think there is something with the code wrong.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. namespace S3
    7. {
    8. public class Player_Inventory : MonoBehaviour {
    9.  
    10.         public Transform inventoryPlayerParent;
    11.         public Transform inventoryUIParent;
    12.         public GameObject uiButton;
    13.  
    14.         private Player_Master playerMaster;
    15.         private GameManager_ToggleInventoryUI inventoryUIScript;
    16.         private float timeToPlaceInHands = 0.1f;
    17.         private Transform currentlyHeldItem;
    18.         private int counter;
    19.         private string buttonText;
    20.         private List<Transform> listInventory = new List<Transform>();
    21.  
    22.     void OnEnable()
    23.     {
    24.             SetInitialReferences();
    25.             UpdateInventoryListAndUI();
    26.             CheckIfHandsEmpty();
    27.  
    28.             playerMaster.EventInventoryChanged += UpdateInventoryListAndUI;
    29.             playerMaster.EventInventoryChanged += CheckIfHandsEmpty;
    30.             playerMaster.EventHandsEmpty += ClearHands;
    31.         }
    32.  
    33.     void OnDisable()
    34.     {
    35.             playerMaster.EventInventoryChanged -= UpdateInventoryListAndUI;
    36.             playerMaster.EventInventoryChanged -= CheckIfHandsEmpty;
    37.             playerMaster.EventHandsEmpty -= ClearHands;
    38.         }
    39.     void SetInitialReferences()
    40.     {
    41.             inventoryUIScript = GameObject.Find("GameManager").GetComponent<GameManager_ToggleInventoryUI>();
    42.             playerMaster = GetComponent<Player_Master>();
    43.     }
    44.  
    45.         void UpdateInventoryListAndUI()
    46.         {
    47.             counter = 0;
    48.             listInventory.Clear();
    49.             listInventory.TrimExcess();
    50.  
    51.             ClearInventoryUI();
    52.  
    53.             foreach (Transform child in inventoryPlayerParent)
    54.             {
    55.                 if (child.CompareTag("Item"))
    56.                 {
    57.                     listInventory.Add(child);
    58.                     GameObject go = Instantiate(uiButton) as GameObject;
    59.                     buttonText = child.name;
    60.                     go.GetComponent<Text>().text = buttonText;
    61.                     int index = counter;
    62.                     go.GetComponent<Button>().onClick.AddListener(delegate { ActivateInventoryItem(index); });
    63.                     go.GetComponent<Button>().onClick.AddListener(inventoryUIScript.ToggleIventoryUI);
    64.                     go.transform.SetParent(inventoryUIParent, false);
    65.                     counter++;
    66.  
    67.                 }
    68.             }
    69.         }
    70.  
    71.         void CheckIfHandsEmpty()
    72.         {
    73.             if(currentlyHeldItem == null&& listInventory.Count > 0)
    74.             {
    75.                 StartCoroutine(PlaceItemInHands(listInventory[listInventory.Count - 1]));
    76.             }
    77.         }
    78.  
    79.         void ClearHands()
    80.         {
    81.             currentlyHeldItem = null;
    82.         }
    83.  
    84.         void ClearInventoryUI()
    85.         {
    86.             foreach(Transform child in inventoryUIParent)
    87.             {
    88.                 Destroy(child.gameObject);
    89.             }
    90.         }
    91.  
    92.         public void ActivateInventoryItem(int inventoryIndex)
    93.         {
    94.             DeactivateAllInventoryItems();
    95.             StartCoroutine(PlaceItemInHands(listInventory[inventoryIndex]));
    96.         }
    97.  
    98.         void DeactivateAllInventoryItems()
    99.         {
    100.             foreach(Transform child in inventoryPlayerParent)
    101.             {
    102.                 if(child.CompareTag("Item"))
    103.                 {
    104.                     child.gameObject.SetActive(false);
    105.                 }
    106.             }
    107.         }
    108.  
    109.         IEnumerator PlaceItemInHands(Transform itemTransform)
    110.         {
    111.             yield return new WaitForSeconds(timeToPlaceInHands);
    112.             currentlyHeldItem = itemTransform;
    113.             currentlyHeldItem.gameObject.SetActive(true);
    114.         }
    115. }
    116.  
    117. }
    118.  
     
  8. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Make sure you have defined the input and then written the exact same thing in the inspector
     
  9. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    You must work backwards and find out why code that you expect to run is not running. Use debug.Log to see what is running and what isn't
     
  10. Mondspringer

    Mondspringer

    Joined:
    Jun 2, 2016
    Posts:
    4
    Thanks for the quick reply.
    I will test it with the Debug Logs

    Edit:
    I forgot a few symbols and corrected them but now thera comes an error from Unity:

    NullReferenceException: Object reference not set to an instance of an object
    S3.Player_Inventory.UpdateInventoryListAndUI () (at Assets/Stranger/Scripts/Player Scripts/Player_Inventory.cs:61)
    S3.Player_Inventory.OnEnable () (at Assets/Stranger/Scripts/Player Scripts/Player_Inventory.cs:25)
     
    Last edited: Sep 3, 2016
  11. Siliwinter

    Siliwinter

    Joined:
    Dec 6, 2015
    Posts:
    15
    Yeah so the problem was that i wrote the "Ammo Name" wrong, on the player its "Assualt Rifle" but on the gun it was "Assault Rifle"
     
  12. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    double click the errors and you'll be taken to where the problem is being identified
     
  13. Mondspringer

    Mondspringer

    Joined:
    Jun 2, 2016
    Posts:
    4
    It brings me ton line 60 " go.GetComponent<Text>().text = buttonText; "
    or to line 64 " go.transform.SetParent(inventoryUIParent, false); "
    and it runs throu everything in this if case.
     
  14. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    sounds like you've forgotten to slot the ui component in the inspector
     
  15. Wambhse

    Wambhse

    Joined:
    Aug 11, 2015
    Posts:
    13
    Not sure if this is where I am suppose to post my Chapter 1 assignment, but here is the link to my youtube video for my chapter 1 assignment for S3. If this is not the right place please let me know where to post it. Thanks. If Any one wants to know about the tweaks I did, I will post a follow up video explaining what I did.



    update: Here is a dropbox link to download a build of the game to try out. You do NOT need a dropbox account to download.

    https://www.dropbox.com/s/pthccqw83z6ccfw/Chapter1.zip?dl=0
     
    Last edited: Sep 7, 2016
  16. Mondspringer

    Mondspringer

    Joined:
    Jun 2, 2016
    Posts:
    4
    No I assigned everyhing and tested to assign other Gameobjects of the Player, but it still wont spawn an item.
     
  17. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Good work! A+
     
  18. primalfearz

    primalfearz

    Joined:
    Feb 5, 2016
    Posts:
    1
    Hello Thanks for the Tuts I am going to being off of the this semester for one of my classes i already know the basics of Unity and such and your videos look to have a whole bunch of new stuff i would like to learn my goal is to finish all the chapters you have out now in about 13 weeks giving my self a week and half each chapter.

    hopefully i can finish this and show u a nice finished product by the end of the semester
     
  19. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    That sounds pretty achievable, I'll look forward to seeing your game!
    In your case my advice is don't worry about graphics, and animations so much, and focus mostly on the fun if you're intending to make your game available for people to play.
     
  20. Saurabh-Saralaya

    Saurabh-Saralaya

    Joined:
    Apr 28, 2016
    Posts:
    23
    Humble Bundle is giving out Game Maker Studio complete for 15$ USD, so.. What is your opinion on Game Maker Studio in Comparison to Unity 2D?
     
  21. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    It doesn't matter what you use, if you make a game that people find fun to play, or a game that inspires people, well then does it really matter? It's up to the devs knowledge, ingenuity, and persistence to make such a game.
     
  22. Saurabh-Saralaya

    Saurabh-Saralaya

    Joined:
    Apr 28, 2016
    Posts:
    23
    True, but Game maker (Free) turned out to be limited and hard to implement, while i was trying it out.
    I just wanted to know if it is worth the time and money i put onto creating the game with it. :)
     
  23. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Lols, you don't go to a hardware store buy tools, wood, structural steel etc. and then think about what you're going to do with it! First you decide what it is that you want to build and then you go about buying the tools and materials you'll need to do the build. :)

    In the same way you need to first have a clear idea in your head of what the game you want to make is about. You should be able to say it in one or two short lines otherwise it's too complicated and won't make sense to anyone apart from yourself. Now that you know what you want to make then you go about getting the relevant game engine.
     
  24. lazalong

    lazalong

    Joined:
    Oct 13, 2009
    Posts:
    139
    Thanks for your excellent tutorials!

    If I may ask, some additions I would love to see how you implement are:
    • NPC Taking Cover script (to heal, hide or shoot from)
    • NPC Intelligence script (some NPCs may hide, other flee and other go in combat against all logic).

    Some other that are probably worth a whole tutorial:
    • Automated Dialogs (i.e. chatting NPCs that randomly triggers some comments in some situations "Good Shoot!", "Wow, nice explosion!", "I am the best", "I am bored" - you know those highly meaningful NPC comments).
    • Scenario System (with objectives to complete, timed events, and conditions triggered events like a cinematic)
    • Load/Save System (I could do one but I am sure yours would be more elegant)
    By cinematic I mean moving the characters in-game and making them perform pre-registered dialogs & movements. Not simply pausing the game and launching a video.
     
  25. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks for the feedback. I'll keep those in mind, the very next update will be dynamic NPC relations. So the actions of NPCs or the player will affect their relationship with other factions. For example if the player shoots at their allies then eventually they will consider the player to be an enemy. The player might destroy something that is important to their allies and so their allies will become their enemies and other NPC factions that were enemies to those former allies will instead become allies to the player!
     
    Wambhse likes this.
  26. theoracle09

    theoracle09

    Joined:
    Sep 12, 2016
    Posts:
    2
    Hi GTGD,

    Thank you so much for your S3 tutorials! I discovered them on Saturday and have just completed your Chapter 1 Assignment (no video, yet, maybe, idk.) I do have a question though on my methods to control the lighting when triggering the enemy spawns, and also when all enemies are dead. It took me several hours to finally make it work, and I just want to see if there's a more efficient way of doing it, so I don't pick up any bad habits.

    When player walks into the cube causing the trigger, I have a public method being referenced from a script attached to my light. I have a detection script attached to my player controller, which checks for the number of enemies in the scene. Once all enemies are dead, I call another public method from my LightControl script, attached to my light. Is the logic sound? Or is there a better way of doing this? I've added all three scripts for anyone to view. Thanks! And I'm happy I can finally move on to Chapter 2.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace Chapter1
    5. {
    6.     public class Trigger_Treasure : MonoBehaviour
    7.     {
    8.         private GameManager_EventMaster eventMasterScript;
    9.         private Welcome treasureMessage;
    10.         private LightControl myLight;
    11.  
    12.         void Start()
    13.         {
    14.             SetInititalReferences();
    15.         }
    16.  
    17.         void OnTriggerEnter(Collider other)
    18.         {
    19.             if(other.tag == "Player")
    20.             {
    21.                 eventMasterScript.CallMyGeneralEvent();
    22.                 Destroy(gameObject);
    23.                 treasureMessage.myTreasureMessage();
    24.                 myLight.DimLight();
    25.             }
    26.         }
    27.  
    28.         void SetInititalReferences()
    29.         {
    30.             if(GameObject.Find("GameManager") != null)
    31.             {
    32.                 eventMasterScript = GameObject.Find("GameManager").GetComponent<GameManager_EventMaster>();
    33.             }
    34.  
    35.             treasureMessage = GameObject.Find("Welcome").GetComponent<Welcome>();
    36.  
    37.             myLight = GameObject.Find("MainLight").GetComponent<LightControl>();
    38.         }
    39.     }
    40. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace Chapter1
    5. {
    6.     public class LightControl : MonoBehaviour
    7.     {
    8.         public Light myLight;
    9.  
    10.         // Use this for initialization
    11.         void Start()
    12.         {
    13.             SetInitialReferences();
    14.         }
    15.  
    16.         // Update is called once per frame
    17.         void Update()
    18.         {
    19.  
    20.         }
    21.  
    22.         void SetInitialReferences()
    23.         {
    24.             if(GameObject.Find("MainLight") != null)
    25.             {
    26.                 myLight = GameObject.Find("MainLight").GetComponent<Light>();
    27.             }
    28.         }
    29.  
    30.         public void DimLight()
    31.         {
    32.             myLight.intensity = 0;
    33.         }
    34.  
    35.         public void NormalLight()
    36.         {
    37.             myLight.intensity = 1;
    38.         }
    39.     }
    40. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace Chapter1
    5. {
    6.     public class Detection : MonoBehaviour
    7.     {
    8.         public GameObject[] enemies;
    9.  
    10.         private float checkRate = 0.5f;
    11.         private float nextCheck;
    12.         private LightControl myLight;
    13.        
    14.  
    15.         // Use this for initialization
    16.         void Start()
    17.         {
    18.             SetInitialReferences();
    19.         }
    20.  
    21.         // Update is called once per frame
    22.         void Update()
    23.         {
    24.             DetectEnemies();
    25.         }
    26.  
    27.         void SetInitialReferences()
    28.         {
    29.             myLight = GameObject.Find("MainLight").GetComponent<LightControl>();
    30.            
    31.         }
    32.  
    33.         void DetectEnemies()
    34.         {
    35.             if(Time.time > nextCheck)
    36.             {
    37.                 nextCheck = Time.time + checkRate;
    38.  
    39.                 enemies = GameObject.FindGameObjectsWithTag("Enemy");
    40.  
    41.                 if (enemies.Length < 1)
    42.                 {
    43.                     myLight.NormalLight();
    44.                 }
    45.             }
    46.         }
    47.     }
    48. }
     
  27. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Very good, I'd also control checking for enemies using a check rate. For more efficiency, if your enemies are on a particular layer then you can use a large overlap sphere that only detects on that layer, rather than GameObject.FindGameObjectsWithTag. Then you can check if the filled in array has a length equal to 0 and from that you'll know if any enemies are still present.

    In the OnTriggerEnter method place the Destroy bit of code as the last instruction of the four to ensure that all the code executes before the GameObject having the script is destroyed.
     
  28. theoracle09

    theoracle09

    Joined:
    Sep 12, 2016
    Posts:
    2
    Thanks for the quick reply! I'll play around with using an overlap sphere and see where that takes me. Also excellent point about the order of execution, I will switch that up. Thanks!
     
  29. Wambhse

    Wambhse

    Joined:
    Aug 11, 2015
    Posts:
    13
    This is something I would really like to see as well!

    Also one way to do the Intelligence script might be to have a "Commander" Script that tells the enemies which attacks to use. That way you don't need up with 10 enemies all throwing their grenades at you at once / or if an enemy is hurt and his friends all have med kits, all his friends don't try to use their med kits at once to heal the injured one.

    I'm sure there are probably better ways to do it. But it was just an idea.
     
  30. PiterQ70

    PiterQ70

    Joined:
    Mar 3, 2015
    Posts:
    82
    Hi GTGD, I'm just made game from your tutorials and i have priblem with [58]Item Pickup

    When I throw item i have error:
    And when i pickup item from ground i have this error:
    code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace AvA
    5. {
    6.     public class Item_Master : MonoBehaviour
    7.     {
    8.  
    9.         private Player_Master playerMaster;
    10.  
    11.         public delegate void GeneralEventHandler();
    12.  
    13.         public event GeneralEventHandler EventObjectThrow;
    14.         public event GeneralEventHandler EventObjectPickup;
    15.  
    16.         public delegate void PickupActionEventHandler(Transform item);
    17.  
    18.         public event PickupActionEventHandler EventPickupAction;
    19.  
    20.  
    21.         // Use this for initialization
    22.         void OnEnable()
    23.         {
    24.             SetInitialReferences();
    25.         }
    26.  
    27.         public void CallEventObjectThrow()
    28.         {
    29.             if(EventObjectThrow != null)
    30.             {
    31.                 EventObjectThrow();
    32.             }
    33.             playerMaster.CallEventHandsEmpty();
    34.             playerMaster.CallEventInventoryChanged();
    35.         }
    36.  
    37.         public void CallEventObjectPickup()
    38.         {
    39.             if(EventObjectPickup != null)
    40.             {
    41.                 EventObjectPickup();
    42.  
    43.             }
    44.             playerMaster.CallEventInventoryChanged();
    45.         }
    46.  
    47.         public void CallEventPickupAction(Transform item)
    48.         {
    49.             if(EventPickupAction != null)
    50.             {
    51.                 EventPickupAction(item);
    52.             }
    53.         }
    54.  
    55.         void SetInitialReferences()
    56.         {
    57.             if(GameManager_References._player != null)
    58.             {
    59.                 playerMaster = GameManager_References._player.GetComponent<Player_Master>();
    60.             }
    61.         }
    62.     }
    63. }
    64.  
    65.  
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace AvA
    5. {
    6.     public class Item_Pickup : MonoBehaviour
    7.     {
    8.  
    9.         private Item_Master itemMaster;
    10.  
    11.         void OnEnable()
    12.         {
    13.             SetInitialReferences ();
    14.             itemMaster.EventPickupAction += CarryOutPickupAction;
    15.         }
    16.  
    17.         void OnDisable()
    18.         {
    19.             itemMaster.EventPickupAction -= CarryOutPickupAction;
    20.         }
    21.  
    22.         void SetInitialReferences()
    23.         {
    24.             itemMaster = GetComponent<Item_Master>();
    25.         }
    26.  
    27.         void CarryOutPickupAction(Transform tParent)
    28.         {
    29.             transform.SetParent(tParent);
    30.             itemMaster.CallEventObjectPickup();
    31.             transform.gameObject.SetActive(false);
    32.         }
    33.     }
    34. }
    35.  
    36.  
    37.  
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace AvA
    5. {
    6.     public class Item_Throw : MonoBehaviour
    7.     {
    8.         private Item_Master itemMaster;
    9.         private Transform myTransform;
    10.         private Rigidbody myRigidbody;
    11.         private Vector3 throwDirection;
    12.  
    13.         public bool canBeThrown;
    14.         public string throwButtonName;
    15.         public float throwForce;
    16.  
    17.         void Start()
    18.         {
    19.             SetInitialReferences();
    20.         }
    21.  
    22.         void Update()
    23.         {
    24.             CheckForThrowInput();
    25.         }
    26.  
    27.         void SetInitialReferences()
    28.         {
    29.             itemMaster = GetComponent<Item_Master>();
    30.             myTransform = transform;
    31.             myRigidbody = GetComponent<Rigidbody>();
    32.         }
    33.  
    34.         void CheckForThrowInput()
    35.         {
    36.             if(throwButtonName !=null)
    37.             {
    38.                 if(Input.GetButtonDown(throwButtonName) && Time.timeScale>0 && canBeThrown && myTransform.root.CompareTag(GameManager_References._playerTag))
    39.                 {
    40.                     CarryOutThrowAction();
    41.                 }
    42.             }
    43.         }
    44.  
    45.         void CarryOutThrowAction()
    46.         {
    47.             throwDirection = myTransform.parent.forward;
    48.             myTransform.parent = null;
    49.             itemMaster.CallEventObjectThrow();
    50.             HurlItem();
    51.         }
    52.  
    53.         void HurlItem()
    54.         {
    55.             myRigidbody.AddForce (throwDirection * throwForce, ForceMode.Impulse);
    56.         }
    57.     }
    58. }
    59.  
    60.  
    61.  

    Where I made a mistake ?


    EDIT: Ohhh....

    I just noticed that these errors occur when the start throw both items . When I choose one of them from inventoryUI and then throw the error does not appear :]
     
    Last edited: Sep 18, 2016
  31. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Try putting SetInitialReferences() in the Start method in the Item_Master script. I think it's a script execution order issue.
     
    PiterQ70 likes this.
  32. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    If there is a specific order of things that must happen then I would probably use one script, but if they are all independent and it doesn't matter what order the particle effect and sound happen in then I would make independent scripts for them. Smaller scripts are automatically easier to understand and maintain when you come back to them months later. As for efficiency you won't notice anything different.
     
  33. Der-Eddy

    Der-Eddy

    Joined:
    Sep 18, 2016
    Posts:
    1
    Tried your tutorial and finally got time to do your first assignment:


    Your videos are the best I could find so far, keep up the good work :)
     
  34. Wambhse

    Wambhse

    Joined:
    Aug 11, 2015
    Posts:
    13
    Hey I just finished video 76 Enemy Nav Pursue and after I was done implementing the script and testing it out, I noticed that when I ran away from the Ice Golmen and turned back around to see where he was at, he had disappeared from the game Window, I ran back to find him and could not. Thinking maybe he fell through the floor or something, I clicked on the Golem gameobject in the Hierarchy and pressed F in the scene view to frame the gameobject, and it centered on him but he was invisible in the Scene window as well. However upon repeating the F key again, the Golem Gameobject reappeared in both the scene and game window. After some testing I found that as soon as the Golem was out of sight from both the scene view/camera and the game view/camera, the Golem gameobject, or rather the Model disappeared. When the Golem was Highlighted the collider was still visible in the Scene window, but not the model. The only way to get the model to show up again was to repeatedly press F to frame him in the scene window and then the model would "pop" visible again. I don't feel like this is a problem with your scripts, I figure it was some sort of setting with my unity that might be causing it. But do you have any idea what might be causing this? I'm using Unity 5.4.0f3. it's not the camera clipping plains, maybe a Unity built in auto scene optimizer or something?

    Update: I did a build of the game, and the Golem does not disappear in the Game Build just inside Unity.

    Update 2: After Reading about The Culling Mode, by your suggestion (GTGD) that seems to be the problem. Switching the Culling mode to Always Animate under the Animator Attached to the Golem. It fixed the problem.
     
    Last edited: Sep 21, 2016
  35. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Double check that the animator component has the culling mode set to always animate. Also double check there are no other animators or animation components present throughout the gameobject
     
  36. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A+ Really excellent work there
    Nice work implementing sound and an enemy counter!
     
  37. Saurabh-Saralaya

    Saurabh-Saralaya

    Joined:
    Apr 28, 2016
    Posts:
    23
    I have Assault Rifle out of my Player (not a bug).
    So i tried to add it back to it.

    I had to
    1.Enable the Animator.
    2.Replace the original position to Item_SetPosition 's local position, and the rotation too.
    3.In Assault Rifle\Canvas Dynamic Crosshair\Canvas replace the dummy camera with WeaponCamera in the Render Camera section.
    4.Disable the Assault rifle GameObject, for the player Inventory to get full Control.

    is there anything else i should do?
     
  38. skinner92

    skinner92

    Joined:
    Feb 23, 2014
    Posts:
    112
    Hey GTGD. First of all, I have just found these tutorials: thank you for the great work in teaching us FPS! :)

    I'd like to ask you something. I can see we can purchase this course through Steam (using this link: http://store.steampowered.com/app/415000). But what's the difference between watching your videos for free on YouTube vs purchasing them from Steam? Do we costumers get any special benefits after purchasing? Is there any special/extra content with the purchase?

    Of course I'd glad to pay for the course, even if not further content is given with the purchase, because I know this video-series is something that requires a lot of your time (which eventually translates into money).

    Thanks! And again, great great work.
     
  39. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    • Don't forget to disable the collider and set the rigidbody to isKinematic.
    • The set position and rotation scripts are probably not needed because the animation will enforce those values.
     
  40. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    You're welcome! The main difference at the moment is the project folder. A completed project folder is included that has content currently beyond what I've covered in tutorials and eventually the tutorials will catch up to the project folder. In the future I need to make some exclusive videos. Trading cards are also included :D
     
    skinner92 likes this.
  41. sujaymb

    sujaymb

    Joined:
    Jun 22, 2016
    Posts:
    1
    Hey GTGD. Thanks for the amazing tutorial. So far I am at the gun reloading part. I just wanted to ask if there is a way to attach a sound to the player. The problem is that, for example, when we reload while moving, the sound is played at a fixed point, as a result the player moves away from the sound. Same thing for the shoot sounds.

    Please advise. Thank you.
     
  42. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    You can attach an AudioSource to the GameObject that the sound is coming from and then adapt the following example from Unity https://docs.unity3d.com/ScriptReference/AudioSource-clip.html
     
  43. PiterQ70

    PiterQ70

    Joined:
    Mar 3, 2015
    Posts:
    82
    GTGD hey ! I creating enemy (model from MIXAMO) and I had a problem. When Enemy TryToAttack and I change the position Enemy move me (slipping) when animation attack play :/ I tried to find an error in the code and in animation controller without success.. Then I found out by adding a few lines of code in Enemy_Attack.cs in TryToAttack() :]
    Code (CSharp):
    1. void TryToAttack()
    2.         {
    3.             if (attackTarget != null)
    4.             {
    5.                 if (Time.time > nextAttack)
    6.                 {
    7.                     nextAttack = Time.time + attackRate;
    8.                     if (Vector3.Distance (myTransform.position, attackTarget.position) <= attackRange) {
    9.                         Vector3 lookAtVector = new Vector3 (attackTarget.position.x, myTransform.position.y, attackTarget.position.z);
    10.                         myTransform.LookAt (lookAtVector);
    11.                         enemyMaster.CallEventEnemyAttack ();
    12.                         enemyMaster.isOnRoute = false;
    13.                         enemyMaster.isNavPaused = true; // stopping enemy in place to end of attack animation
    14.  
    15.                     } else {
    16.                         enemyMaster.isNavPaused = false;  //cancellation
    17.                     }
    18.  
    19.                 }
    20.             }
    21.         }

    Now it works properly. When the enemy attack is in place. Ends attack moves me.

    But is this the best solution?

    BTW. Sorry for my bad english :D
     
  44. PiterQ70

    PiterQ70

    Joined:
    Mar 3, 2015
    Posts:
    82
    Hello I added to the script sneaking. Maybe for someone be useful :] It works so that if enemy detect player is executed animation sneaking to given radius and then enemy walk.

    You need add new animation sneak and make transition bool "isSneaking" to Idle like Walk transiton.



    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace AvA
    5. {
    6.     public class Enemy_Animation : MonoBehaviour
    7.     {
    8.  
    9.         private Enemy_Master enemyMaster;
    10.         private Animator myAnimator;  
    11.  
    12.         void OnEnable()
    13.         {
    14.             SetInitialReferences();
    15.             enemyMaster.EventEnemyDie += SetAnimationToDie;
    16.             enemyMaster.EventEnemyWalking += SetAnimationToWalk;
    17.             enemyMaster.EventEnemySneak += SetAnimationToSneak;
    18.             //enemyMaster.EventEnemyRuning += SetAnimationToRuning; //running animation
    19.             enemyMaster.EventEnemyReachedNavTarget += SetAnimationToIdle;
    20.             enemyMaster.EventEnemyAttack += SetAnimationToAttack;
    21.             enemyMaster.EventEnemyDeductHealth += SetAnimationToGetHit;
    22.  
    23.         }
    24.  
    25.         void OnDisable()
    26.         {
    27.             enemyMaster.EventEnemyDie -= SetAnimationToDie;
    28.             enemyMaster.EventEnemyWalking -= SetAnimationToWalk;
    29.             enemyMaster.EventEnemySneak -= SetAnimationToSneak;
    30.             //enemyMaster.EventEnemyRuning -= SetAnimationToRuning; //running animation
    31.             enemyMaster.EventEnemyReachedNavTarget -= SetAnimationToIdle;
    32.             enemyMaster.EventEnemyAttack -= SetAnimationToAttack;
    33.             enemyMaster.EventEnemyDeductHealth -= SetAnimationToGetHit;
    34.         }
    35.  
    36.         void SetInitialReferences()
    37.         {
    38.             enemyMaster = GetComponent<Enemy_Master>();
    39.  
    40.             if (GetComponent<Animator>() != null)
    41.             {
    42.                 myAnimator = GetComponent<Animator>();
    43.             }
    44.                
    45.         }
    46.  
    47.         void SetAnimationToWalk()
    48.         {
    49.             if (myAnimator != null)
    50.             {
    51.                 if(myAnimator.enabled)
    52.                 {
    53.                     myAnimator.SetBool("isSneaking", false); //stop sneaking when walking
    54.                     myAnimator.SetBool("isPursuing", true);
    55.                 }
    56.             }
    57.         }
    58.  
    59.         void SetAnimationToSneak()
    60.         {
    61.             if (myAnimator != null)
    62.             {
    63.                 if(myAnimator.enabled)
    64.                 {
    65.                     myAnimator.SetBool ("isPursuing", false); //stop walking when sneaking
    66.                     myAnimator.SetBool("isSneaking", true);
    67.                 }
    68.             }
    69.         }
    70.  
    71.         //void SetAnimationToRuning()
    72.         //{
    73.         //    if (myAnimator != null)
    74.         //    {
    75.         //        if(myAnimator.enabled)
    76.         //        {
    77.         //            myAnimator.SetBool ("isRuning", true);
    78.         //        }
    79.         //    }
    80.         //}
    81.  
    82.         void SetAnimationToIdle()
    83.         {
    84.             if(myAnimator != null)
    85.             {
    86.                 if(myAnimator.enabled)
    87.                 {
    88.                     myAnimator.SetBool ("isPursuing", false);
    89.                     myAnimator.SetBool ("isSneaking", false); //stop sneaking when idle
    90.                     //myAnimator.SetBool ("isRuning", false); // stop running when idle
    91.                 }
    92.             }
    93.         }
    94.  
    95.         void SetAnimationToAttack()
    96.         {
    97.             if(myAnimator != null)
    98.             {
    99.                 if(myAnimator.enabled)
    100.                 {
    101.                     myAnimator.SetTrigger("isAttack");
    102.                 }
    103.             }
    104.         }
    105.  
    106.         void SetAnimationToGetHit(int dummy)
    107.         {
    108.             if(myAnimator != null)
    109.             {
    110.                 if(myAnimator.enabled)
    111.                 {
    112.                     myAnimator.SetTrigger("getHit");
    113.                 }
    114.             }
    115.         }
    116.  
    117.         void SetAnimationToDie()
    118.         {
    119.             if(myAnimator != null)
    120.             {
    121.                 if(myAnimator.enabled)
    122.                 {
    123.                     //myAnimator.SetTrigger("isDead");
    124.                     myAnimator.enabled = false;
    125.                 }
    126.                 //myAnimator.enabled = false;
    127.             }
    128.         }
    129.     }
    130. }
    131.  
    132.  
    133.  

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace AvA
    5. {
    6.     public class Enemy_NavPursue : MonoBehaviour
    7.     {
    8.  
    9.         private Enemy_Master enemyMaster;
    10.         private NavMeshAgent myNavMeshAgent;
    11.         private float checkRate;
    12.         private float nextCheck;
    13.         public float sneakDistance = 50; //distance to stop sneak
    14.  
    15.         void OnEnable()
    16.         {
    17.             SetInitialReferences();
    18.             enemyMaster.EventEnemyDie += DisableThis;
    19.         }
    20.  
    21.         void OnDisable()
    22.         {
    23.             enemyMaster.EventEnemyDie -= DisableThis;
    24.         }
    25.  
    26.         void Update()
    27.         {
    28.             if (Time.time > nextCheck)
    29.             {
    30.                 nextCheck = Time.time + checkRate;
    31.                 TryToChaseTarget();
    32.             }
    33.         }
    34.  
    35.         void SetInitialReferences()
    36.         {
    37.             enemyMaster = GetComponent<Enemy_Master>();
    38.             if(GetComponent<NavMeshAgent>() != null)
    39.             {
    40.                 myNavMeshAgent = GetComponent<NavMeshAgent>();
    41.             }
    42.  
    43.             checkRate = Random.Range(0.1f, 0.2f);
    44.             Debug.Log(checkRate);
    45.         }
    46.  
    47.         void TryToChaseTarget()
    48.         {
    49.             if (enemyMaster.myTarget != null && myNavMeshAgent != null && !enemyMaster.isNavPaused)
    50.             {
    51.                
    52.                 myNavMeshAgent.SetDestination (enemyMaster.myTarget.position);
    53.  
    54.                 if (myNavMeshAgent.remainingDistance > myNavMeshAgent.stoppingDistance)
    55.                     {
    56.                     if (myNavMeshAgent.remainingDistance >= sneakDistance) {
    57.                         enemyMaster.CallEventEnemySneak ();
    58.                         enemyMaster.isOnRoute = true;
    59.                     } else if (myNavMeshAgent.remainingDistance <= sneakDistance) {
    60.                         enemyMaster.CallEventEnemyWalking ();
    61.                         enemyMaster.isOnRoute = true;
    62.                     }
    63.                     }
    64.             }
    65.         }
    66.  
    67.         void DisableThis()
    68.         {
    69.             if (myNavMeshAgent != null)
    70.             {
    71.                 myNavMeshAgent.enabled = false;
    72.             }
    73.  
    74.             this.enabled = false;
    75.         }
    76.     }
    77. }
     
  45. Demondarem

    Demondarem

    Joined:
    Aug 31, 2016
    Posts:
    2
    Thank you for making those videos
    this is my game Abandoned Hunter

    Download link is in the description
     
    Raf2756 likes this.
  46. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Your solution looks fine. Once you get to chapter 9 you will implement a better AI system and hopefully you won't have the same inconvenience :)
     
  47. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Definite A!
    Very good work for a first game project!
     
  48. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    After you complete chapter 9 you'll find that you are capturing the attacker in a variable called myAttacker. I'm going to extend that for another purpose in some upcoming videos. You'll be able to use the contents of that variable and I'm sure you'll be able to develop your own system for writing to a UI.
     
  49. Wambhse

    Wambhse

    Joined:
    Aug 11, 2015
    Posts:
    13
    When doing [176] Setup Ranged Ally 2 - How To Make A Game I ran into a problem. When adjusting the gun's position and the left and right hand targets like you did in your video. I noticed that when you "Played" the scene the gun (on Max Ranged Ally) stayed in the location you adjusted it to when the scene wasn't playing. However for me, after adjusting the position of the gun on Max and when I played the scene, the gun snapped into the floor. The Gun still moved and animated properly, it just moved along the floor of the scene instead of his hands like I placed it. After tracking down the problem I found that it was the animator that was causing it. The animator for the gun was originally created for the player, and the position of the gun was key framed for the player not Max. In order to get around this I created an empty game object and put it above the Assault Rifle of Max. I called the Empty Game object Weapon Offset. Then I adjusted the position of Weapon Offset and placed the Gun back into his hands after the idle animation moved the gun in the floor. My question was, what did I do wrong? You didn't seem to have this problem with your Max ally or the gun animator. Why did I? does this mean if people decided to change the idle animation then it wouldn't for other allies / enemies, or if different size allies / enemies were used then it wouldn't work either? I'm just trying to figure out what I might have done wrong, and fix it.

    Also one other thing I noticed just now is when My Max Ranged Ally dies, the item he drops does not drop where he dies but drops at the same location every time. No matter how far we travel. Or where he dies. The Gun drops in the same location every time. It only does that on the Ally, not the Golems. I have combed through all the scripts, I can't figure out why it's doing that.

    update 1: I did find out that when I put another item on max ally and he dies then the item drops where it is suppose to be.

    update 2: looks like it's because the animator is on when the item drops. I need to update the scripts so that the animator is turned off before the item is thrown. One problem down!.
     
    Last edited: Oct 17, 2016
  50. Saurabh-Saralaya

    Saurabh-Saralaya

    Joined:
    Apr 28, 2016
    Posts:
    23

    I had the same problem, along with the Max 's Ragdoll rotating violently once he died. I had to redo whole of the Max Ragdoll to get it working. Well I'll be doing the Ranged weapon again, l'll tell you about my progress soon.

    Edit: Well I have a new problem, The pivot point of Assault rifle is misplaced and it doesn't reset back to the geometry.

    Edit 2:I got mine working somehow.
     
    Last edited: Oct 16, 2016