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
    Well I don't cover grappling hooks but your other request is already covered in S3 :)
     
    YED likes this.
  2. YED

    YED

    Joined:
    Jul 26, 2016
    Posts:
    6
    So, do you have any idea about how can I learn this grappling hook thing :)
     
  3. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    When you've gone through these tutorials you should have enough knowledge of the Unity API to develop what you are trying to do. First of all you need to write down for yourself what the grappling hook is supposed to do. Then write down how you are going to achieve that. From there you can figure out what are the subsystems you need to develop to make each aspect of your grappling hook work. Once you've finally got it all going make a YouTube video to show your grappling hook in action and share the video here because it will be interesting to see it in action!
     
    EvilGremlin likes this.
  4. YED

    YED

    Joined:
    Jul 26, 2016
    Posts:
    6
    So if I will do that, I need to watch all the videos :p And I am in chapter 1 now. Maybe I can post the video a few months later :D Thank you <3 I love your tutorials. My English is not very good but you are educating very well in your videos. I have your all stuff in my Steam account. Good luck <3
     
  5. iamtheprogram

    iamtheprogram

    Joined:
    Aug 1, 2016
    Posts:
    1
    Here is mine:
     
  6. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A, Nice work!
    Thanks for posting. For a moment I imagined the monsters were forklifts!
     
  7. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Ok well all the best with your studying then! I'll look forward to your work in some months from now
     
  8. Saurabh-Saralaya

    Saurabh-Saralaya

    Joined:
    Apr 28, 2016
    Posts:
    23
    Hello! I just completed video 155, and the State Melee is acting funny, it changes to melee attack and then flips between Patrol and Alert State. even if i am in the melee range
     
  9. Saurabh-Saralaya

    Saurabh-Saralaya

    Joined:
    Apr 28, 2016
    Posts:
    23
    Oh wait. Never-mind that i found another video called Improved Melee Attack.
     
  10. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Yup once you've completed that it's all good :D
     
  11. Mancyy

    Mancyy

    Joined:
    Jul 18, 2016
    Posts:
    1
    I only implemented the bare bones requirements, but all the features are there and the lighting changes.

    Video of project:

     
  12. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A+ Excellent work
    All required features implemented, good job!
     
  13. lazalong

    lazalong

    Joined:
    Oct 13, 2009
    Posts:
    139
    Excellent tutorials

    What do you think about removing the 'if' in the event handler?

    Nearly all your classes are of the structure:

    Code (CSharp):
    1.     public class ClassName: MonoBehaviour {
    2.  
    3.  
    4.         private AMaster master;
    5.         private AComponent component;
    6.  
    7.         void OnEnable()
    8.         {
    9.             SetReferences();
    10.             master.EventSomething += DoSomething;
    11.         }
    12.  
    13.         void OnDisable()
    14.         {
    15.             master.EventSomething -= DoSomething;
    16.         }
    17.  
    18.         void SetReferences()
    19.         {
    20.             master= GetComponent<AMaster>();
    21.  
    22.             if (GetComponent<Component>() != null)
    23.             {
    24.                 component = GetComponent<Component>();
    25.             }
    26.         }
    27.  
    28.         void DoSomething()
    29.         {
    30.             if (component!= null)
    31.             {
    32.                 component.DoIt();
    33.             }
    34.         }
    35.     }
    36.  
    Do you see an issue with changing the structure to the following code.

    I know that your code is safer but as the UnsetReferences() isn't public we can prevent countless 'if' tests. I would only had the test if in a class you want to make the Set/Unset methods public to be able to change a class behaviour (although even in this case it shouldn't cause an issue if one is careful).


    Code (CSharp):
    1.     public class ClassName: MonoBehaviour {
    2.  
    3.         private AMaster master;
    4.         private AComponent component;
    5.  
    6.         void OnEnable()
    7.         {
    8.             SetReferences();
    9.         }
    10.  
    11.         void OnDisable()
    12.         {
    13.             UnsetReferences;
    14.         }
    15.  
    16.         void SetReferences()
    17.         {
    18.             master= GetComponent<AMaster>();
    19.  
    20.             if (GetComponent<Component>() != null)
    21.             {
    22.                 component = GetComponent<Component>();
    23.                 master.EventSomething += DoSomething;
    24.             }
    25.         }
    26.  
    27.          void UnsetReferences()
    28.         {
    29.             if (component != null)
    30.             {
    31.                 master.EventSomething -= DoSomething;
    32.                 component = null;
    33.             }
    34.         }
    35.  
    36.         void DoSomething()
    37.         {
    38.             component.DoIt();
    39.         }
    40.     }
    41.  
     
    Last edited: Aug 6, 2016
  14. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I think the ideal is if one can write their code in such a way that it fails to safe so that the player might just experience a bug, but not a major crash. My code isn't always fail to safe, but in my game titles such as Weekend Drive I always try to write the code so that it doesn't have a serious crash if I've made a mistake in my setup.
     
  15. Saurabh-Saralaya

    Saurabh-Saralaya

    Joined:
    Apr 28, 2016
    Posts:
    23
    Hi there! I have completed 159th video [NPC Animations] and the Golem is acting funny again, most the time the Pursue() method or the whole of Pursue State not being called (just a deduction based on materialFlag). And the provided scripts looks different. I am really confused now , should i move on to the next videos and will it come up somewhere to fix or should i traverse through my scripts trying to find the bugs?
     
  16. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Keep on going onwards :)
     
    Last edited: Aug 9, 2016
    Saurabh-Saralaya likes this.
  17. NPBirader

    NPBirader

    Joined:
    Feb 23, 2015
    Posts:
    20
    I have a problem with the enemy. It first starts patroling and he goes to the alert state. Everything normal but he stays in the alert state he not pursues. Im going to another position and wait until he sees me and comes to me but he doesnt go to the pursue state. Only if im far away from him and sometimes,he notices me and goes after a while to pursue. Dont know what the problem is i checked the scripts no different...
     
  18. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Up to what video have you reached?
     
  19. NPBirader

    NPBirader

    Joined:
    Feb 23, 2015
    Posts:
    20
    I noticed this after i wrote the pursue state. Now i have finished the videos.
     
  20. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Maybe the detection count is too high and make sure that you've completed video 162
     
  21. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    Could you please make a tutorial of Loading scene [Game menu > loading scene > Game level] ?
    I tried to do this in my game but i could not. You did not explain it in you YT channel.
     
  22. NPBirader

    NPBirader

    Joined:
    Feb 23, 2015
    Posts:
    20
    The detectioncount is standart 15. I checked the StatePattern, Patrol, Alert, pursue scripts but nothing different. Maybe it dependy because of the Unity 5.4 verison. Could it be?
     
  23. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I'm not intending to do this at the moment but I think you would use SceneManager.LoadSceneAsync and also SceneManager.sceneLoaded
     
  24. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    No it's not Unity, you'll have to scrutinise your code and your layers setup. You must determine why your AI is unable to go into the Pursue state so start examining all your code that leads to a pursue state. Use debug.log to figure out what code is running and what code that should be running isn't
     
  25. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    • Maybe you could have a manager script with an array on it.
    • When an enemy is instantiated it will access the manager and add itself to the array.
    • The spawner GameObject can have a reference to this manager and it will pass on the reference to each enemy it instantiates.
    • A list might be more convenient in your case because it is easy to remove entries from a list.
     
    Raf2756 likes this.
  26. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    The new GTGD S3 Trailer. The Steam package now includes a project folder with what you see in this trailer!

     
    Raf2756 and Saurabh-Saralaya like this.
  27. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    Its important thing ! Evey one of your fans one day will ask about this. Game maker can not avoid this.
     
    Raf2756 likes this.
  28. JC_LEON

    JC_LEON

    Joined:
    May 20, 2014
    Posts:
    518

    and the old scene?? can we mantain the old demo too??
     
  29. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    • You can still play the old built winter demo, it's in the Steam Package in a folder, but I won't be doing any further work on that demo and I might eventually remove it.
    • The reason is simple, I can't distribute the project folder for that scene because it has paid assets in it.
    • In future I'll only maintain the new scene because I can continue to distribute that project folder.
     
  30. JC_LEON

    JC_LEON

    Joined:
    May 20, 2014
    Posts:
    518
    ok thanks..
     
  31. lazalong

    lazalong

    Joined:
    Oct 13, 2009
    Posts:
    139
    In video [131] Pocket Hut Part 1, you are using the Wooden Hut asset.
    I don't know if it is new but the package is using a LOD Group component and there are three meshes and renderers as child of the game object. Hence your script will not work directly on the asset. You need to extract one of the mesh, probably Woodenhut_LOD0, from the Wooden Hut prefab.

    I would suggest to either mention it in the video or - if you have time and it would be awesome - update the script so that it can apply to game objects having a LOD Group component. Of course, it would also mean one set of shards for each three meshes.

    I hacked the Item_Transparency script. It now works because when you are near the LOD0 mesh is the first to be found by GetComponentInChildren().

    Code (CSharp):
    1.         void CaptureStartingMaterial()
    2.         {
    3.             if (GetComponent<Renderer>() != null)
    4.             {
    5.                 primaryMaterial = GetComponent<Renderer>().material;
    6.             }
    7.             else if (GetComponentInChildren<Renderer>() != null)
    8.             {
    9.                 primaryMaterial = GetComponentInChildren<Renderer>().material;
    10.             }
    11.         }
    12.  
    13.         void SetToPrimaryMaterial()
    14.         {
    15.             if (GetComponent<Renderer>() != null)
    16.             {
    17.                 GetComponent<Renderer>().material = primaryMaterial;
    18.             }
    19.             else if (GetComponentInChildren<Renderer>() != null)
    20.             {
    21.                 GetComponentInChildren<Renderer>().material = primaryMaterial;
    22.             }
    23.  
    24.         }
    25.  
    26.         void SetToTransparentMaterial()
    27.         {
    28.             if (GetComponent<Renderer>() != null)
    29.             {
    30.                 GetComponent<Renderer>().material = transparentMaterial;
    31.             }
    32.             else if (GetComponentInChildren<Renderer>() != null)
    33.             {
    34.                 GetComponentInChildren<Renderer>().material = transparentMaterial;
    35.             }
    36.         }
     
    Last edited: Aug 18, 2016
    EvilGremlin likes this.
  32. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    That means you would just drop the hut in the scene, pull out the relevant GameObject, delete the others and make a prefab out of that. I know for certain that people will come to that conclusion when they think about it, and I would expect anyone making it this far into the series to be more than capable of taking care of that :cool:.

    Making three sets of shards is not logical, because if they are not removed from the scene then if it's a low quality one, the player will see that when they come close - ugly :eek:. Any other child GameObjects that are disabled will be deleted anyway when the Destructible GameObject is destroyed.
     
  33. lazalong

    lazalong

    Joined:
    Oct 13, 2009
    Posts:
    139
    argh... I updated my message with some code while you answered.

    Having several set of shards can be logical if you know that you can't get near enough before the shards self-destroy.
     
    Last edited: Aug 18, 2016
  34. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Hmm.. I don't get what all the material changing is for, but if it works for what you are doing then all good!
     
  35. plrmaker7

    plrmaker7

    Joined:
    Aug 18, 2016
    Posts:
    5
    First off, excellent tutorial!

    Having an issue with Melee weapons....

    When I select a melee weapon from the inventory - the first time I equip it to use, as soon as I use it (Fire1) it starts to move away from the player. When I equip it the second time and swing it, it stays in the correct position. So every odd time a melee weapon is equipped it moves away in position with every swing. Any ideas?

    Thank you!
     
  36. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    sounds like your animation is moving it about
     
  37. plrmaker7

    plrmaker7

    Joined:
    Aug 18, 2016
    Posts:
    5
    Yeah, that is what I initially thought, but when I run it in the animation window, the position doesn't change. Going to keep searching.... Thanks for the reply!
     
  38. plrmaker7

    plrmaker7

    Joined:
    Aug 18, 2016
    Posts:
    5
    Still have not figure it out. Now it exhibits this behavior:

    Scenario 1:

    1. Start with Sword - swing animation works fine
    2. Switch to Crowbar (or Sword) - once swing animation starts - weapon starts to "slide" off of player.
    3. Switch to Sword or Crowbar - swing animation works fine

    Scenario 2:

    1. Start with Crowbar - once swing animation starts - weapon starts to "slide" off of player.
    2. Switch to Sword (or Crowbar) - swing animation works fine
    3. Switch to Crowbar (or Sword) - once swing animation starts - weapon starts to "slide" off of player.


    I have redone all animation and re-positioned weapons on player with no success at solving this. Could I have missed something in a script somewhere or doing something incorrect in my animations?

    *Also, if I start the game with Player Inventory script disabled and only use the sword - it works fine, can even throw and pick up and swinging works fine....

    Thanks again!
     
  39. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Make sure root motion on the Animator is switched off. The rigidbody and collider do become active during a swing but the animation exerts control over the motion of the melee weapon otherwise it would "slide" off the player.

    Also try removing an Item_Set Position or Rotation script if one is on the weapon.
     
  40. plrmaker7

    plrmaker7

    Joined:
    Aug 18, 2016
    Posts:
    5
    Still happening. But, going to keep on trying to solve this! Thanks again for your help!
     
  41. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Here's your answer :)
     
    EvilGremlin likes this.
  42. NPBirader

    NPBirader

    Joined:
    Feb 23, 2015
    Posts:
    20
    Oh man i had done vehicles with the jet too but i deleted it because the standart assets vehicle controll is very strange and if i was going out of my car it was driving forever and the collisions didnt worked by me. I will go on with you.
     
  43. EvilGremlin

    EvilGremlin

    Joined:
    Aug 12, 2016
    Posts:
    231
    This is the best Unity tutorial anybody has ever made. I am only on chapter 2 but I am very impressed. I wish I had started it before trying some of the others.
     
  44. NPBirader

    NPBirader

    Joined:
    Feb 23, 2015
    Posts:
    20
    I played around with some Gunholding Animations for the Npc by just simply replacing the old Animations and disabling the ik stuff for the gun on the npc and animator. I created a Emty Gameobject, called it Holder, attached the gun to it and made it as a child of the Right npc hand. This way i can rotate the Holder to the right position i like. Now its looking good. Smooth walking and idle but i havent figured out how i can manage the shooting anim since its happening through the gun.
    If i could figure it out i would use some of these animations.
    Some solutions?
     
  45. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Use your gun holding animations. Maybe there is one that has the effect of the gun jolting as it is fired. If not you could rotate the gun by code.
     
  46. NPBirader

    NPBirader

    Joined:
    Feb 23, 2015
    Posts:
    20
    I mean i have no problems. The npc animator has idle walk melee attack and struck states. I want to know how i should make the gun shooting state. The normal shooting anim is called by the gun but the npc needs the shooting state instead of the gun if i can explain
     
  47. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    You'll need a new state to the animator of course and a new trigger. You'll have to modify the master and animation scripts so that the new trigger can be called, and then modify the relevant NPC scripts so that it is called. The animation can probably come from Any State.
     
  48. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    You need to add a lot more detail to your question
     
  49. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    • you have some work to do
    • your animator could have two struck states with different triggers or maybe you can use a blend tree with both animations in it and it is affected by a 0 or 1 value.
    • Your master script and animation event methods may need to change to account for this added variable.
    • the one who is attacked will need to know whether they were range or melee attacked.
    • Then you call the appropriate event, melee struck or range struck
     
  50. NPBirader

    NPBirader

    Joined:
    Feb 23, 2015
    Posts:
    20
    Done it. Looks good but i have a question. I have done this by simply checking for the "has shootingAnim" boolean i created in the statepattern.Im calling the new animation with the npcinput. However i had to change the gun_animator for that. Because i had no idea how i would get the statepattern from that i created a new bool "hasNpcShootingAnim" in the gun_Master. Now i dont want to have this. Im getting errors if i am accsesing the statepatter. I know the solution must be easy but i have no idea how i would do that.