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. Scorpion005

    Scorpion005

    Joined:
    Jul 3, 2017
    Posts:
    2
    Hi and thanks for your tutorials
    I've got a problem with enemy detection code the error in the picture Picture.jpg
    and this is my code
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5. namespace S3
    6. {
    7.     public class Enemy_Detection : MonoBehaviour {
    8.  
    9.         private Enemy_Master enemyMaster;
    10.         private Transform myTransform;
    11.         public Transform head;
    12.         public LayerMask playerLayer;
    13.         public LayerMask sightLayer;
    14.         private float checkRate;
    15.         private float nextCheck;
    16.         public float detectRadius;
    17.         private RaycastHit hit;
    18.  
    19.         void OnEnable()
    20.         {
    21.             SetInitialRefrences();
    22.             enemyMaster.EventEnemyDie+=DisableThis;
    23.            
    24.         }
    25.  
    26.  
    27.  
    28.         void OnDisable()
    29.         {
    30.             enemyMaster.EventEnemyDie -= DisableThis;
    31.         }
    32.  
    33.  
    34.         void Update ()
    35.         {
    36.             CarryOutDetection();
    37.         }
    38.  
    39.  
    40.         void SetInitialRefrences()
    41.         {
    42.             enemyMaster = GetComponent<Enemy_Master>();
    43.             myTransform = transform;
    44.             if (head = null)
    45.             {
    46.                 head = myTransform;
    47.             }
    48.  
    49.             checkRate = Random.Range(0.8f, 1.2f);
    50.         }
    51.  
    52.         void CarryOutDetection()
    53.         {
    54.             if (Time.time > nextCheck)
    55.             {
    56.                 nextCheck = Time.time + checkRate;
    57.  
    58.  
    59.                 Collider[] colliders = Physics.OverlapSphere(myTransform.position, detectRadius, playerLayer);
    60.  
    61.                 if (colliders.Length > 0)
    62.                 {
    63.                     foreach (Collider target in colliders)
    64.                     {
    65.                         if (target.CompareTag(GameManager_Refrences._playerTag))
    66.                         {
    67.                             if (CanBeseen(target.transform))
    68.                             {
    69.                                 break;
    70.                             }
    71.                         }
    72.                     }
    73.                 }
    74.  
    75.                 else
    76.                 {
    77.                     enemyMaster.CallEventEnemyLostTarget();
    78.                 }
    79.             }
    80.         }
    81.  
    82.         bool CanBeseen(Transform target)
    83.         {
    84.             if (Physics.Linecast(head.position, target.position, out hit, sightLayer))
    85.             {
    86.                 if (hit.transform == target)
    87.                 {
    88.                     enemyMaster.CallEventEnemySetNavTarget(target);
    89.                     return true;
    90.                 }
    91.                 else
    92.                 {
    93.                     enemyMaster.CallEventEnemyLostTarget();
    94.                     return false;
    95.                 }
    96.             }
    97.             else
    98.             {
    99.                 enemyMaster.CallEventEnemyLostTarget();
    100.                 return false;
    101.             }
    102.  
    103.  
    104.         }
    105.        
    106.         void DisableThis()
    107.         {
    108.             this.enabled = false;
    109.         }
    110.     }
    111. }
    also this is my enemy master code
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5. namespace S3
    6. {
    7.     public class Enemy_Master : MonoBehaviour
    8.     {
    9.  
    10.         public Transform myTarget;
    11.  
    12.         public delegate void GeneralEventHandler();
    13.         public event GeneralEventHandler EventEnemyDie;
    14.         public event GeneralEventHandler EventEnemyWalking;
    15.         public event GeneralEventHandler EventEnemyReachedNavTarget;
    16.         public event GeneralEventHandler EventEnemyAttack;
    17.         public event GeneralEventHandler EventEnemyLostTarget;
    18.  
    19.         public delegate void HealthEventHandler(int health);
    20.         public event HealthEventHandler EventEnemyDeductHealth;
    21.  
    22.         public delegate void NavTargetEventHandler(Transform targetTransform);
    23.         public event NavTargetEventHandler EventEnemySetNavTarget;
    24.  
    25.         public void CallEventEnemyDeductHealth(int health)
    26.         {
    27.             if (EventEnemyDeductHealth != null)
    28.             {
    29.                 EventEnemyDeductHealth(health);
    30.             }
    31.         }
    32.  
    33.         public void CallEventEnemySetNavTarget(Transform targTransform)
    34.         {
    35.             if (EventEnemySetNavTarget != null)
    36.             {
    37.                 EventEnemySetNavTarget(targTransform);
    38.             }
    39.  
    40.             myTarget = targTransform;
    41.         }
    42.  
    43.         public void CallEventEnemyDie()
    44.         {
    45.             if (EventEnemyDie != null)
    46.             {
    47.                 EventEnemyDie();
    48.             }
    49.         }
    50.  
    51.         public void CallEventEnemyWalking()
    52.         {
    53.             if (EventEnemyWalking != null)
    54.             {
    55.                 EventEnemyWalking();
    56.             }
    57.         }
    58.  
    59.         public void CallEventEnemyReachedNavTarget()
    60.         {
    61.             if (EventEnemyReachedNavTarget != null)
    62.             {
    63.                 EventEnemyReachedNavTarget();
    64.             }
    65.         }
    66.  
    67.  
    68.         public void CallEventEnemyAttack()
    69.         {
    70.             if (EventEnemyAttack != null)
    71.             {
    72.                 EventEnemyAttack();
    73.             }
    74.         }
    75.  
    76.         public void CallEventEnemyLostTarget()
    77.         {
    78.             if (EventEnemyLostTarget != null)
    79.             {
    80.                 EventEnemyLostTarget();
    81.             }
    82.             myTarget = null;
    83.         }
    84.     }
    85. }
    help me pelase
     
  2. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    Wondering if anybody has encountered this problem and has a solution:

    Video 32, I've completed the GameManagerMaster, GameManagerPauseToggle, and GameMangerToggleMenu scripts. Been over every line and it all runs without any compilers errors, yet the time will not pause when the menu is active. I can still move around.


    UPDATE:

    Couldn't find any solution to this problem, so I just continued on. Once I added the Player Toggle script it started working as expected, though somehow now that is messing with the cursor lock -- disabling it.
     
    Last edited: Jul 9, 2017
  3. Yobeeno

    Yobeeno

    Joined:
    Jul 22, 2017
    Posts:
    2
    Added my Project 1 Assignment video on YouTube. Hope you like.
     
  4. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A++ Really Excellent!
    The ending boss fight is a nice touch
     
  5. Yobeeno

    Yobeeno

    Joined:
    Jul 22, 2017
    Posts:
    2
    Wow - Thanks very much! BTW Your tutorials are top notch too. Thanks for sharing!
     
  6. doppie320

    doppie320

    Joined:
    Feb 13, 2017
    Posts:
    7
    Is it normal for the burst fire to be active without the hasburstfire bool active?
     
  7. Scorpion005

    Scorpion005

    Joined:
    Jul 3, 2017
    Posts:
    2
    did any one find the answer?
     
  8. marcelolecram

    marcelolecram

    Joined:
    Jan 22, 2016
    Posts:
    4
    Thanks a lot for the course!
    It really help me a lot
    anyway this is my assignment for chapter 1

    PS i suck at art :p
     
  9. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A+, Great work!
    I really like the moving platforms! Sorry I didn't see your video sooner, I've been away for a bit.
     
  10. Saurabh-Saralaya

    Saurabh-Saralaya

    Joined:
    Apr 28, 2016
    Posts:
    23
    Is there a way to attach, IEnumerators onto Events?

    Code (CSharp):
    1. itemMaster.EventObjectThrow += DestroyUsingTimer;
    2.  
    3. //to
    4.  
    5. itemMaster.EventObjectThrow += BeginExplosionTimer;
    6.  
    Code (CSharp):
    1.         void DestroyUsingTimer()
    2.         {
    3.             //new WaitForSeconds(waitTime);
    4.  
    5.             if (GetComponent<Item_Pickup>() != null)
    6.             {
    7.                 GetComponent<Item_Pickup>().enabled = false;
    8.             }
    9.  
    10.             StartCoroutine(BeginExplosionTimer());
    11.         }
    12.  
    13.         IEnumerator BeginExplosionTimer()
    14.         {
    15.             yield return new WaitForSeconds(waitTime);
    16.             destructibleMaster.CallEventDestroyMe();
    17.         }
    I think it could be simplified into a single function
    But WaitForSeconds() did not execute in the function.
     
  11. Saurabh-Saralaya

    Saurabh-Saralaya

    Joined:
    Apr 28, 2016
    Posts:
    23
    I published my game, on IndieDB
    It's a Procedurally generated Arcade titled Expunge!

    Download it here: http://www.indiedb.com/games/expunge

    I did not use Evil max, Portable Hut or Vehicles just yet, probably soon :p
     
    Last edited: Oct 4, 2017
  12. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Well that is it everyone, all good things have to come to an end, and video 210 is the final video for GTGD S3 :)
    Thanks for being part of an incredible journey and I hope you have benefited a lot. I'll certainly be making an effort to see your assignments and play your games. Saurabh's game is on my list of games to play :).

    Btw, I'm working on the new GTGD S1, Unity 2017 multiplayer tutorial. You'll see a video for it soon hopefully. It's very different from the original S1 but I believe a lot more useful and I've made it more focused on the important and more commonly used aspects of the Unity multiplayer system. You can try out the built project now. You can download it from my website here. The new GTGD S1 will replace the product on Steam. While I might release a few of the new S1 videos on YouTube, the complete tutorial will be available through Steam.
     
    Saurabh-Saralaya and Sonnenspeer like this.
  13. Smiderplanen

    Smiderplanen

    Joined:
    Sep 11, 2017
    Posts:
    2
    i really need ur help i get this error in console when trying to pickup ammo:

    NullReferenceException: Object reference not set to an instance of an object
    Item_Ammo.TakeAmmo () (at Assets/Scripts/Item Scripts/Item_Ammo.cs:62)


    Here is my Item_Ammo Code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Item_Ammo : MonoBehaviour
    6. {
    7.     private Item_Master itemMaster;
    8.     private GameObject playerGo;
    9.     public string ammoName;
    10.     public int quantity;
    11.     public bool isTriggerPickup;
    12.  
    13.     void OnEnable()
    14.     {
    15.         SetInitialReferences();
    16.         itemMaster.EventObjectPickup += TakeAmmo;
    17.     }
    18.  
    19.     void OnDisable()
    20.     {
    21.         itemMaster.EventObjectPickup -= TakeAmmo;
    22.     }
    23.  
    24.     void Start()
    25.     {
    26.         SetInitialReferences();
    27.     }
    28.  
    29.     void OnTriggerEnter(Collider other)
    30.     {
    31.         if (other.CompareTag(GameManager_References._playerTag) && isTriggerPickup)
    32.         {
    33.             TakeAmmo();
    34.         }
    35.             if (other.CompareTag(GameManager_References._playerTag))
    36.             {
    37.                 TakeAmmo();
    38.             }
    39.         }
    40.  
    41.     void SetInitialReferences()
    42.     {
    43.         itemMaster = GetComponent<Item_Master>();
    44.         playerGo = GameManager_References._player;
    45.  
    46.         if (isTriggerPickup)
    47.         {
    48.             if (GetComponent<Collider>() != null)
    49.             {
    50.                 GetComponent<Collider>().isTrigger = true;
    51.             }
    52.  
    53.             if (GetComponent<Rigidbody>() != null)
    54.             {
    55.                 GetComponent<Rigidbody>().isKinematic = true;
    56.             }
    57.         }
    58.     }
    59.  
    60.     void TakeAmmo()
    61.     {
    62.         playerGo.GetComponent<Player_Master>().CallEventPickedUpAmmo(ammoName, quantity);
    63.         Destroy(gameObject);
    64.     }
    65. }
    66.  
    Here is my Item_Master Script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Item_Master : MonoBehaviour
    6. {
    7.     private Player_Master playerMaster;
    8.     public GameObject playerController;
    9.  
    10.     public delegate void GeneralEventHandler();
    11.     public event GeneralEventHandler EventObjectThrow;
    12.     public event GeneralEventHandler EventObjectPickup;
    13.  
    14.     public delegate void PickupActionEventHandler(Transform item);
    15.     public event PickupActionEventHandler EventPickupAction;
    16.  
    17.     void OnEnable()
    18.     {
    19.         SetInitialReferences();
    20.     }
    21.  
    22.     void Start()
    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.         playerMaster.CallEventInventoryChanged();
    44.     }
    45.  
    46.     public void CallEventPickupAction(Transform item)
    47.     {
    48.         if (EventPickupAction != null)
    49.         {
    50.             EventPickupAction(item);
    51.  
    52.         }
    53.     }
    54.  
    55.     void SetInitialReferences()
    56.     {
    57.         if (GameManager_References._player != null)
    58.         {
    59.             //playerMaster = GameObject.Find("Player").GetComponent<Player_Master>();
    60.             playerMaster = playerController.GetComponent<Player_Master>();
    61.             //playerMaster = GameManager_References._player.GetComponent<Player_Master>();
    62.          
    63.         }
    64.     }
    65. }
    and here is my Player_Master Script:
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class Player_Master : MonoBehaviour
    7. {
    8.     public delegate void GeneralEventHandler();
    9.     public event GeneralEventHandler EventInventoryChanged;
    10.     public event GeneralEventHandler EventHandsEmpty;
    11.     public event GeneralEventHandler EventAmmoChanged;
    12.  
    13.     public delegate void AmmoPickupEventHandler(string ammoName, int quantity);
    14.     public event AmmoPickupEventHandler EventPickedUpAmmo;
    15.  
    16.     public delegate void PlayerHealthEventHandler(int healthChange);
    17.     public event PlayerHealthEventHandler EventPlayerHealthDeduction;
    18.     public event PlayerHealthEventHandler EventPlayerHealthIncrease;
    19.  
    20.     public void CallEventInventoryChanged()
    21.     {
    22.         if(EventInventoryChanged != null)
    23.         {
    24.             EventInventoryChanged();
    25.         }
    26.     }
    27.  
    28.     public void CallEventHandsEmpty()
    29.     {
    30.         if(EventHandsEmpty != null)
    31.         {
    32.             EventHandsEmpty();
    33.         }
    34.     }
    35.  
    36.     public void CallEventAmmoChanged()
    37.     {
    38.         if(EventAmmoChanged != null)
    39.         {
    40.             EventAmmoChanged();
    41.         }
    42.     }
    43.  
    44.     public void CallEventPickedUpAmmo(string ammoName, int quantity)
    45.     {
    46.         if(EventPickedUpAmmo != null)
    47.         {
    48.             EventPickedUpAmmo(ammoName, quantity);
    49.         }
    50.     }
    51.  
    52.     public void CallEventPlayerHealthDeduction(int dmg)
    53.     {
    54.         if(EventPlayerHealthDeduction != null)
    55.         {
    56.             EventPlayerHealthDeduction(dmg);
    57.         }
    58.     }
    59.  
    60.     public void CallEventPlayerHealthIncrease(int increase)
    61.     {
    62.         if(EventPlayerHealthIncrease != null)
    63.         {
    64.             EventPlayerHealthIncrease(increase);
    65.         }
    66.     }
    67. }
    68.  
    Can u please tell me whats wrong? Need another bit of code? tell me i post u
    i must use public GameObject playerController;
    and playerMaster = playerController.GetComponent<Player_Master>(); in Item Master or else my UI Inventory button dosent reset :|
     
    Last edited: Oct 25, 2017
  14. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    It might be that the player master is not setting up the reference to the player GameObject in time. A script execution order problem. If that is the case try setting up the reference to the player GameObject in Awake in the GameManager_References script.
     
  15. RandomGuardian83

    RandomGuardian83

    Joined:
    Sep 18, 2017
    Posts:
    1
    Hey I'm on episode 98 and I'm getting the null reference exception error on line 41 and I don't know why, the code looks exactly as it should. Thoughts?
    Code (CSharp):
    1. private GunMaster gunMaster;
    2.     private float nextAttack;
    3.     public float attackRate = 0.5f;
    4.     private Transform myTransform;
    5.     public bool isAutomatic;
    6.     public bool hasBurstFire;
    7.     private bool isBurstFireActive;
    8.     public string attackButtonName;
    9.     public string reloadButtonName;
    10.     public string burstFireButtonName;
    11.  
    12.  
    13.  
    14.     void Start () {
    15.        
    16.     }
    17.    
    18.     // Update is called once per frame
    19.     void Update () {
    20.         CheckIfWeaponShouldAttack ();
    21.         CheckForBurstFireToggle ();
    22.         CheckForReloadRequest ();
    23.     }
    24.  
    25.     void SetInitialReferences()
    26.     {
    27.         gunMaster = GetComponent<GunMaster> ();
    28.         myTransform = transform;
    29.         gunMaster.isGunLoaded = true;  //allows the player to shoot right away
    30.     }
    31.  
    32.     void CheckIfWeaponShouldAttack()
    33.     {
    34.         if (Time.time > nextAttack && Time.timeScale > 0 &&
    35.             myTransform.root.CompareTag(GameManagerReferences._playerTag)) {
    36.             if (isAutomatic && !isBurstFireActive) {
    37.                 if (Input.GetButton (attackButtonName)) {
    38.                     Debug.Log ("Full Auto Fire");
    39.                     AttemptAttack ();
    40.                 }
    41.             } else if (isAutomatic && isBurstFireActive) {
    42.                 if (Input.GetButtonDown (attackButtonName)) {
    43.                     Debug.Log ("Burst Fire Firing");
    44.                     StartCoroutine (RunBurstFire ());
    45.                 }
    46.             }
    47.  
    48.             else if (!isAutomatic) {
    49.                 if (Input.GetButtonDown (attackButtonName)) {
    50.                     AttemptAttack ();
    51.                 }
    52.             }
    53.         }
    54.     }
    55.  
    56.     void AttemptAttack()
    57.     {
    58.         nextAttack = Time.time + attackRate;
    59.         if (gunMaster.isGunLoaded) {
    60.             Debug.Log ("Shooting");
    61.             gunMaster.CallEventPlayerInput ();
    62.         } else {
    63.             gunMaster.CallEventGunNotUsable ();
    64.         }
    65.     }
    66.  
    67.     void CheckForReloadRequest()
    68.     {
    69.         if (Input.GetButtonDown (reloadButtonName) && Time.timeScale > 0 && myTransform.root.CompareTag (GameManagerReferences._playerTag)) {
    70.             gunMaster.CallEventRequestReload ();
    71.             Debug.Log ("player is reloading and cannot fire");
    72.         }
    73.     }
    74.  
    75.     void CheckForBurstFireToggle()
    76.     {
    77.         if (Input.GetButtonDown (burstFireButtonName) && Time.timeScale > 0 && myTransform.root.CompareTag (GameManagerReferences._playerTag)) {
    78.             Debug.Log ("Burst Fire Toggled");
    79.             isBurstFireActive = !isBurstFireActive;
    80.             gunMaster.CallEventToggleBurstFire ();
    81.         }
    82.     }
    83.  
    84.     IEnumerator RunBurstFire()
    85.     {
    86.         AttemptAttack ();
    87.         yield return new WaitForSeconds (attackRate);
    88.         AttemptAttack ();
    89.         yield return new WaitForSeconds (attackRate);
    90.         AttemptAttack ();
    91.     }
    92. }
    93.  
     

    Attached Files:

  16. aidinz

    aidinz

    Joined:
    Apr 17, 2016
    Posts:
    63
    For the FPS tutorial, are you using a pre-made character controller or write one from scratch?

    EDIT: It uses the Standard Asset's character controller.

    I really wished it would teach how to write a 3D character controller.
     
    Last edited: Nov 23, 2017
  17. Nizzio

    Nizzio

    Joined:
    Jan 9, 2016
    Posts:
    1


    Chapter 1 Challenge
     
  18. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A+ Nicely Done :)
     
  19. scoobz1234

    scoobz1234

    Joined:
    Aug 2, 2016
    Posts:
    4
    Hey All, having a problem once i got to Episode 120, the Destructible_ParticleSpawn script i'm getting null reference for the Initialization method.. i was thinking this may be a script execution error, anyone else having any issue?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. namespace ScoobzGame{
    6.  
    7. public class Destructible_ParticleSpawn : MonoBehaviour {
    8.  
    9.         private Destructible_Master destructibleMaster;
    10.         public GameObject explosionEffect;
    11.  
    12.         void OnEnable () {
    13.             InitRef();
    14.             destructibleMaster.EventDestroyMe += SpawnExplosion;
    15.         }
    16.  
    17.         void OnDisable () {
    18.             destructibleMaster.EventDestroyMe -= SpawnExplosion;
    19.         }
    20.  
    21.         private void Start() {
    22.             InitRef();
    23.             destructibleMaster.EventDestroyMe += SpawnExplosion;
    24.         }
    25.  
    26.         void InitRef(){
    27.             destructibleMaster.GetComponent<Destructible_Master>();
    28.         }
    29.  
    30.         void SpawnExplosion() {
    31.             if (explosionEffect != null) {
    32.                 Instantiate(explosionEffect, transform.position, Quaternion.identity);
    33.             }
    34.         }
    35.     }
    36.  
    37. }
    EDIT: i found that if i make the private Destructible_Master script public, and drag and drop in the script to the field in the inspector, the error goes away...
     
    Last edited: Mar 30, 2018
    KUFgoddess likes this.
  20. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    That's a good solution. I do that quite a bit myself these days to avoid any such issue.
     
    scoobz1234 likes this.
  21. KUFgoddess

    KUFgoddess

    Joined:
    Apr 2, 2015
    Posts:
    27

    I was having those same types of problems a few months ago. I started realizing if I have a null reference that means there isn't a reference, nothing is there or whatever was there is not being called. Now I am able to fix a lot of the different satiations that output a null reference.
     
  22. kingmaker1331

    kingmaker1331

    Joined:
    Apr 10, 2017
    Posts:
    3
    Hey..!Very Awesome tutorials...
    I am Developing my First FPS Game And your tutorials are helping me so much .
    Actually i want to develop it for Mobile Phone.
    i am not much play games on PC.So Can You Or Any One help me for Mobile Inputs.
    Any free kit from unity Assets store.Or how to just put buttons and use them for input.
    Thank you.
     
  23. kingmaker1331

    kingmaker1331

    Joined:
    Apr 10, 2017
    Posts:
    3
    I Also Got This Error But Solved By Rewriting Code of Enemy_Animations. Some times unity Goes Mad.You can try by rewriting code.Look at the problem in which script it cause and rewrite code. Thanks
     
  24. hongwaixuexi

    hongwaixuexi

    Joined:
    Dec 11, 2017
    Posts:
    857
    GTGD:
    It's a very useful tutorial.
    Could you continue on AI FSM? The npc who uses ranged weapon should step back when enemy approach closely, and now they just moving forward.

    Any plan for new tutorial? I hope still on FPS with many details.
     
  25. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks. The npc goes into the pursue state quite regularly so when they are in the range attack state you could alter the code so they don't go into the pursue state. This will stop them moving towards the enemy. You could alter the range attack state further and borrow a bit from the flee state so they do move back and try to keep away from the enemy.

    It was my intention to create an AI series, because since GTGD S3 I've made my AIs quite a lot more efficient, but Unity has brought in the ECS (Entity Component System - Data Oriented Design) API and it is early days at the moment. ECS to me looks like the future of coding in Unity with MonoBehaviour becoming legacy, but Unity still has a ton of work to do to make ECS as feature rich. For me I'm not keen on making tools, I want to make games so I have to wait till ECS is mature. I would like to make tutorials for ECS and I keep thinking I should, but I really wish Unity made the implementation more complete before releasing it.
     
  26. hongwaixuexi

    hongwaixuexi

    Joined:
    Dec 11, 2017
    Posts:
    857
    Thanks for your advice on adaption. I watched a lot videos and assets, no AI code is as simple as yours while powerful. I also hope you can add some melee fight tutorial like doom4.
     
  27. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    @GTGD

    I'd like to say thank you because your series from 2012 got the ball rolling for me making FPS games.
    It started out fairly rough in quality, but it has now become this.

    It's not the same code as yours, but this goes to show that with enough research into networking and gameplay anyone can pull off a polished experience.



    BTW, any chance you will be attempting to write a series for the ECS networking engine?
     
    GTGD likes this.
  28. sujazoya

    sujazoya

    Joined:
    Jul 10, 2018
    Posts:
    4

    using UnityEngine;
    using UnityEngine.UI;

    namespace S3
    {

    public class Player_HealthPlus : MonoBehaviour
    {
    private Item_Master item_Master;
    private Player_Master player_Master;
    private GameObject plaryerGo;
    public int quntity;
    public bool isTriggerPickup;
    public AudioSource healthAudio;

    void OnEnable()
    {
    SetInitialReferences();
    item_Master.EventObjectPickup += TakeAmmo;

    }

    void OnDisable()
    {
    item_Master.EventObjectPickup -= TakeAmmo;
    }

    // Use this for initialization
    void Start()
    {
    SetInitialReferences();

    }

    void OnTriggerEnter(Collider other)
    {
    if (other.CompareTag(tag: GameManager_References._playerTag) && isTriggerPickup)
    {
    TakeAmmo();
    }
    }

    void SetInitialReferences()
    {
    healthAudio = GetComponent<AudioSource>();
    item_Master = GetComponent<Item_Master>();
    plaryerGo = GameManager_References._player;

    if (isTriggerPickup)
    {
    if (GetComponent<Collider>() != null)
    {
    GetComponent<Collider>().isTrigger = true;
    }
    if (GetComponent<Rigidbody>() != null)
    {
    GetComponent<Rigidbody>().isKinematic = true;
    }

    }
    }
    void TakeAmmo()
    {
    plaryerGo.GetComponent<Player_Master>().CallEventEventPlayerHealthInrease(quntity);
    healthAudio.Play();
    Destroy(gameObject);
    }
    }
    }
     
  29. KenjiJU

    KenjiJU

    Joined:
    Dec 31, 2012
    Posts:
    20
    Edit: Alrighty! I solved my issue indirectly.

    Apparently having my character break prefabs was causing the problem. Now I can throw the cubes like before.

    I'm going to continue on with the project.

    Thanks a lot GTGD :)

    -------------------------

    Hello.

    I'm getting NullReferenceException when picking up or throwing objects. I can pick them up, but they don't throw properly. They were previously throwing properly until I started working on the weapon section.

    I'd appreciate some help because this has had me stumped.

    The code fails at lines 24 and 34.

    Code (CSharp):
    1. public class ItemMaster : MonoBehaviour {
    2.  
    3.     private PlayerMaster playerMaster;
    4.     private GameManager_References references;
    5.  
    6.     public delegate void GeneralEventHandler();
    7.     public event GeneralEventHandler EventObjectThrow;
    8.     public event GeneralEventHandler EventObjectPickup;
    9.  
    10.     public delegate void PickupActionEventHandler(Transform item);
    11.     public event PickupActionEventHandler EventPickupAction;
    12.  
    13.     void Start() // changed from OnEnable
    14.     {
    15.         SetInitialReferences();
    16.     }
    17.  
    18.     public void CallEventObjectThrow()
    19.     {
    20.         if(EventObjectThrow != null)
    21.         {
    22.             EventObjectThrow();
    23.         }
    24.         playerMaster.CallEventHandsEmpty();
    25.         playerMaster.CallEventInventoryChanged();
    26.     }
    27.  
    28.     public void CallEventObjectPickup()
    29.     {
    30.         if(EventObjectPickup != null)
    31.         {
    32.             EventObjectPickup();
    33.         }
    34.         playerMaster.CallEventInventoryChanged();
    35.     }
    36.  
    37.     public void CallEventPickupAction(Transform item)
    38.     {
    39.         if(EventPickupAction != null)
    40.         {
    41.             EventPickupAction(item);
    42.         }
    43.     }
    44.  
    45.     void SetInitialReferences()
    46.     {
    47.         if(GameManager_References._player != null)
    48.         {
    49.             references = GetComponent<GameManager_References>();
    50.             playerMaster = GameManager_References._player.GetComponent<PlayerMaster>();
    51.         }
    52.     }
    53. }
     
    Last edited: Dec 17, 2018
  30. alexchernitsyn

    alexchernitsyn

    Joined:
    Nov 14, 2018
    Posts:
    2
    Hello everyone here is my post for the S3 Chapter 1 Assignment was trying to make it before new years but obs was not working for me and i didn't want to deal with it and then there was winter break so i took the 2 weeks off. Also i am gonna make a video with commentary going through how i did it cause i am curious if my way is Inefficient and can be done better




    Edit 1: oh yeah also forgot to mention that i found a bug at the end of the video but its pretty fun to mess around with so i kept it but i assume the way you fix that bug is to make a grenade layer set it to the grenade prefab and then have player and grenade layer not interact with each other
     
  31. alexchernitsyn

    alexchernitsyn

    Joined:
    Nov 14, 2018
    Posts:
    2


    Here is the commentary video BTW excuse my stutters please i was pretty nervous for some stupid reason
     
  32. IbraheemAli

    IbraheemAli

    Joined:
    Dec 31, 2018
    Posts:
    3
    I am having trouble in the Item_UI script. When I run the game, the UI on the object shows as normal, but when I throw it and then pick it up it doesn't show. How could I fix this.

    PS: Here is the code that I wrote:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. namespace S3{
    6.     public class Item_UI : MonoBehaviour
    7.     {
    8.         private Item_Master itemMaster;
    9.         public GameObject myUI;
    10.         void OnEnable(){
    11.             SetInitialReferences();
    12.             itemMaster.EventObjectPickUp += EnableMyUI;
    13.             itemMaster.EventObjectThrow += DisableMyUI;
    14.         }
    15.  
    16.         void OnDisable(){
    17.             itemMaster.EventObjectPickUp -= EnableMyUI;
    18.             itemMaster.EventObjectThrow -= DisableMyUI;
    19.         }
    20.  
    21.         void SetInitialReferences(){
    22.             itemMaster = GetComponent<Item_Master>();
    23.         }
    24.  
    25.         void EnableMyUI(){
    26.             if(myUI != null){
    27.                 myUI.SetActive(true);
    28.             }
    29.         }
    30.  
    31.         void DisableMyUI(){
    32.             if(myUI != null){
    33.                 myUI.SetActive(false);
    34.             }
    35.         }
    36.     }
    37. }
     
  33. Kehel

    Kehel

    Joined:
    Apr 27, 2015
    Posts:
    1
    Hi! Simple proj by the end of Chepter 1
     
  34. Portal-2-GLaDOS

    Portal-2-GLaDOS

    Joined:
    Apr 23, 2017
    Posts:
    1
    Funnily enough I bought GTGD back in 2017 on my birthday, But I had only gotten enough time to really work on watching the series until around now, I've spent a couple days working on it and I think I've finished Chapter 1's assignment, I didn't think it was possible but I managed to do it.



    PS: Ignore the typo during the battle sequence, It's supposed to say "your research" not "you research", Only noticed the typo after recording and editing the video.
     
  35. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Nice video and good work with the assignment. I'd set the code to check for no enemies every few seconds like you were thinking.
     
  36. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Good work both of you!
    I like the level design Portal.

     
  37. rkerketta

    rkerketta

    Joined:
    Nov 15, 2019
    Posts:
    1
    Please upload assets.
     
  38. barryshebs

    barryshebs

    Joined:
    Dec 31, 2020
    Posts:
    1
    Is this still active?