Search Unity

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

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

  1. KandoGames

    KandoGames

    Joined:
    Dec 7, 2015
    Posts:
    9
    Starting on these now :) Can't wait !! Hope it's a good introduction to the series, and since I have a slight programming background maybe I can provide some extra scripts for people. Wish me luck !
     
  2. Puppy_GC

    Puppy_GC

    Joined:
    Feb 14, 2016
    Posts:
    2
    Last edited: Feb 20, 2016
  3. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Good luck :)
     
  4. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A+ for excellent work! I played the game and it's pretty good. There's shadow flickering over the grass so you can try the following:
    Try setting your camera near clipping plane to 0.3 or 0.4 if it is less than that.
    Double check that the player and all the action is within 3000 units or so of the 0,0,0 world co-ordinates.
    If you have a weapon camera then double check that it isn't observing the terrain as well.
    Try setting your lighting settings so that you are only using precomputed GI and not baked lightmapping as well.
    Clear your GI cache as well.
    Check that your gameobjects are set to cast shadows and maybe just turn off cast shadows for the rpg
     
    Last edited: Feb 20, 2016
  5. Puppy_GC

    Puppy_GC

    Joined:
    Feb 14, 2016
    Posts:
    2
    Thank you for tips will try it
    Also i'll try upload new video when i finish chapter 2, hopefully i can get animation working by this time :)
     
  6. KandoGames

    KandoGames

    Joined:
    Dec 7, 2015
    Posts:
    9
    Just started episode 16 :)

    Can't wait to get further

    Are you planning on teaching Aim Down sights, and maybe having a couple of hands with the gun etc? And maybe switching weapon animation etc?

    Great series so far :D
     
  7. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Great to hear! No I'm not covering aiming down sights (you could do that with an animation) or having hands. Much later on you'll see that the guns will have basic animations that you'll make.
     
  8. KandoGames

    KandoGames

    Joined:
    Dec 7, 2015
    Posts:
    9
    Oh, so in most FPS games, Aiming down sights is literally Taking the gun closer? As in the sights would actually have to be attached to the gun? I sort of assumed it gave the illusion of that but it was ore complex, lol.


    Thanks!
     
  9. LionW

    LionW

    Joined:
    Mar 6, 2015
    Posts:
    1

    Here is my assignment, its simple but i made it. :D
     
  10. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    It might be or maybe the main camera moves closer. Yes the sights should be attached to the gun. I'm not sure but the shooting raycast might also have to be emitted from the sights for it to be accurate
     
  11. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Really nice work! A+ and a nice destructible environment!
     
  12. KandoGames

    KandoGames

    Joined:
    Dec 7, 2015
    Posts:
    9
    Hey. Does anyone have the project files for the end of Video 20? I was doing really well, then accidentally deleted a few assets and it all messed up real bad. Everything is simply a miss. GTGD if you have the files, or anyone else. Even if its sort of close (Little behind or little ahead) I don't mind... Thanks!

    Edit: GTGD Himself was kind enough to send me the file, So I got it. Thanks :D
     
    Last edited: Mar 3, 2016
  13. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    So here what my project look like
    www.googledrive.com/host/0B-w2Hbfj2CabOGZTbGtydjh1VDQ

    • Added gunbob to the gun
    • Added Camera shake when the explosion happens
    • Added Aimsightsdown option
    • Added Sway Effect
    • Added Smooth gun movement
    • Added Gun Recoil
    • Fixed the "golem" legs aren't really attached to the ground in animation (Actually u can do that to any animation)
    • Dynamic Crosshair (WIP)
     
    Last edited: Mar 6, 2016
  14. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    The link doesn't work, maybe it isn't public? Make a video of what you've done so that anyone passing by can see it
     
  15. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
  16. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    I just played it and it looks really neat. You just need to solve some of the camera blur stuff because the UI is getting blurry when running. I personally don't like gun movement but the explosion camera shake is a nice touch. You should consider making a YouTube video so at least that way you can see how your project changes over time. It will also give you a tiny bit of exposure early on.
     
  17. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    Thank you, I'll fix all those bugs and i'll upload some videos on youtube about it updates :)
     
  18. mynameisgabe

    mynameisgabe

    Joined:
    Oct 20, 2012
    Posts:
    5
    Last edited: Mar 9, 2016
  19. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    A+ Fantastic stuff!
    Really interesting pulsing glow on the enemies and nice environmental change

    Btw, you might want to just share the built project folder rather than your source folder, that will keep the size down and allow people to more conveniently play it
     
    Last edited: Mar 9, 2016
  20. mynameisgabe

    mynameisgabe

    Joined:
    Oct 20, 2012
    Posts:
    5
    Thanks! I updated the download to be just an export of the scene (unitypackage file), which included just the required dependancies I think. So now it's only 53MB or so.
     
  21. marcs77

    marcs77

    Joined:
    Jul 14, 2013
    Posts:
    4
    Hi! I've made a script template for Visual Studio so that you don't have to switch to Unity to create them, plus it doesn't get removed when you update unity. Just put it in Documents\Visual Studio 2015\Templates\ItemTemplates, don't extract it.
     

    Attached Files:

  22. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    Thank you, i was too lazy to write it :p
     
  23. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Thanks for that!
     
  24. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    Hi there GTGD,
    Last day i was working on my project using the Raycast, and then i found a problem with raycast,
    Sometimes it works and most of times it doesn't, the problem is that it goes only horizontally and ignoring vertical, i tried using Debug.DrawRay, and as i told you it doesn't go UP and Down
    While the Ray Transform Pivot is the FirstPersonCharacter Camera and it actually goes vertical and horizontal normally
    Can you help me please, that bug i couldn't fix it,
    If you want the project just tell me, i can send you in time
     
  25. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    The ray only originates where you tell it to and only goes in the direction you tell it to. So obviously you're telling it to have the direction of something that never tilts up or down and there's your problem
     
  26. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    No, the pivot is FirstPersonCharecter as you did in ur video,but it works,
    and sometimes it doesn't work, even the raycast of the gun does the same,is it a bug or something ?
     
  27. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    No there's something wrong with your code. The ray should be fired from the FirstPersonCharacter. If you can move your mouse and look around then there's no reason why you can't shoot a ray in the same direction you are looking unless the code if faulty.
     
  28. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    After millions of debugs, i found that the raycast gets broken after i pause the game, when i open the inventroy
    So is it from disable the controller or
     
  29. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Hmm well keep searching for the problem methodically and you'll eventually pinpoint it
     
  30. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    The problem was disabling the FirstPersonController and fixed it by editing on the FPS Script and TogglePlayerScript
     
  31. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64

    I've uploaded an update video (Watch on 60fps)
     
    Last edited: Mar 15, 2016
  32. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Nice work, looks very good now!
     
  33. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
  34. mynameisgabe

    mynameisgabe

    Joined:
    Oct 20, 2012
    Posts:
    5
    I'm on video 84 and something weird is happening to my monster when i hit him with a box. He's going into convulsions after being hit with a box. maybe I missed something with the ragdoll? Here's a quick video.

     
  35. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Lol that does look pretty bad, check that your ragdoll is setup correctly (T pose and all that) and also check Enable Projection on all of the Character Joint components
     
  36. mynameisgabe

    mynameisgabe

    Joined:
    Oct 20, 2012
    Posts:
    5
    i tried enable projection checked on all the joints and it does the same thing.

    i'll try starting the enemy section over again. do you think it could be a bug in my script? if not, i'll just reuse the scripts i have and just focus on the ragdoll configuration.
     
  37. mynameisgabe

    mynameisgabe

    Joined:
    Oct 20, 2012
    Posts:
    5
    OK - I think I figured it out. I accidentally attached the "Enemy_TakeDamage" script on most of the joints instead of the "Enemy_ActivateRagdoll" script. I removed TakeDamage and added ActivateRagdoll and now the enemy falls to the ground normally without twirling around like a tornado.

    Thanks!
     
  38. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Good work, though I'm starting to take a liking to that whirling around like a tornado effect :D
     
  39. Hghdra

    Hghdra

    Joined:
    Mar 28, 2016
    Posts:
    1
    I'm on episode 51, and was wondering, how do you change the colour of the item name on the GUI? I want it to be black
     
  40. Deleted User

    Deleted User

    Guest

    Hi!
    I have already tweeted to you on twitter, however thought i'd post here too as I cannot find the issue at all! :(

    The issue i'm having is as follows;

    I have a weapon already attached to my player, which is enabled when I drop in.

    I pick up a second weapon, everything runs fine, it gets added to my inventory and I can select it. Also when it is thrown the next weapon (the only one left in the inventory) will appear in my hand, which is good!

    However, when I pick up the third weapon, doesn't matter what order I pick them up in.. the third weapon will not disable and will be active on top of the weapon thats currently in hand.. both shoot at the same time, both reload ect.. and when thrown it throws both of them out at the same time.

    If I go into the inventory and select a weapon it will correct the issue and only one gun will be active.. however, when that weapon is thrown no other weapon will be activated which means I have to go back into the inventory to select one.


    I've re run through multiple videos and cannot for the life of me spot one difference :/ this maybe either I'm just missing it somewhere, i'm not looking at the correct script or.. it's something thats not set correctly in the inspector!

    Any advice on this will be very much appreciated as I am developing my game as a project for my university 3D Environments & Game Interaction assignment.

    I can post up scripts, but not sure what ones I'd need to post!

    Please Help! :)
     
  41. Deleted User

    Deleted User

    Guest

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine.UI;
    5.  
    6. public class Player_Inventory : MonoBehaviour {
    7.  
    8.     public Transform inventoryPlayerParent;
    9.     public Transform inventoryUIParent;
    10.     public GameObject uiButton;
    11.  
    12.     private Player_Master playerMaster;
    13.     private GameManager_ToggleInventoryUI inventoryUIScript;
    14.     private float timeToPlaceInHands = 0.1f;
    15.     private Transform currentlyHeldItem;
    16.     private int counter;
    17.     private string buttonText;
    18.     private List<Transform> listInventory = new List<Transform> ();
    19.  
    20.  
    21.     void OnEnable()
    22.     {
    23.         SetInitialReferences ();
    24.         UpdateInventoryListAndUI (); //Inventory List gets filled up on start UI updated.
    25.         DeactivateAllInventoryItems();
    26.         CheckIfHandsEmpty(); //If player does not have item in hand, but has in inventory, it will put the last picked up weapon in hands.
    27.  
    28.         playerMaster.EventInventoryChanged += UpdateInventoryListAndUI;
    29.         playerMaster.EventInventoryChanged += CheckIfHandsEmpty;      //Subscriptions
    30.         playerMaster.EventInventoryChanged += ClearHands;
    31.     }
    32.  
    33.     void OnDisable()
    34.     {
    35.         playerMaster.EventInventoryChanged -= UpdateInventoryListAndUI;
    36.         playerMaster.EventInventoryChanged -= CheckIfHandsEmpty;  //Unsubscribing
    37.         playerMaster.EventInventoryChanged -= ClearHands;
    38.     }
    39.  
    40.     void SetInitialReferences()
    41.     {
    42.         inventoryUIScript = GameObject.Find ("GameManager").GetComponent<GameManager_ToggleInventoryUI> (); //Setting References
    43.         playerMaster = GetComponent<Player_Master> ();
    44.     }
    45.  
    46.     void UpdateInventoryListAndUI()
    47.     {
    48.         counter = 0;
    49.         listInventory.Clear ();
    50.         listInventory.TrimExcess ();
    51.  
    52.         ClearInventoryUI ();
    53.  
    54.         foreach (Transform child in inventoryPlayerParent)
    55.         {
    56.             if (child.CompareTag ("Item"))
    57.             {
    58.                 listInventory.Add (child);
    59.                 GameObject go = Instantiate (uiButton) as GameObject; //Setting up Button
    60.                 buttonText = child.name; //Setting Button Name
    61.                 go.GetComponentInChildren<Text>().text = buttonText;
    62.                 int index = counter;
    63.                 go.GetComponent<Button> ().onClick.AddListener (delegate { ActivateInventoryItem(index);});
    64.                 go.GetComponent<Button> ().onClick.AddListener (inventoryUIScript.ToggleInventoryUI);
    65.                 go.transform.SetParent (inventoryUIParent, false);
    66.                 counter++;
    67.             }
    68.         }
    69.     }
    70.  
    71.     void CheckIfHandsEmpty() //Has the player got items in the inventory, activate last item in the inventory list
    72.     {
    73.         if (currentlyHeldItem == null && listInventory.Count > 0)
    74.         {
    75.             StartCoroutine (PlaceItemInHands (listInventory [listInventory.Count - 1])); //Placing last item in inventory in hands
    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); //Inventory Buttons!!
    89.         }
    90.     }
    91.  
    92.     public void ActivateInventoryItem(int inventoryIndex) //Buttons in the inventory to activate the items
    93.     {
    94.         DeactivateAllInventoryItems (); //Deactivate all inventory items to prevent having more than one active item.
    95.         StartCoroutine (PlaceItemInHands (listInventory[inventoryIndex]));//Looking through the list, and activating whichever item was selected via buttons
    96.     }
    97.  
    98.     void DeactivateAllInventoryItems()
    99.     {
    100.         foreach (Transform child in inventoryPlayerParent) //going through all items carried by the player
    101.         {
    102.             if (child.CompareTag ("Item"))
    103.             {
    104.                 child.gameObject.SetActive (false); //All objects with item layer will be disabled, to prevent having two active at the same time
    105.             }
    106.         }
    107.     }
    108.  
    109.     IEnumerator PlaceItemInHands(Transform itemTransform)
    110.     {
    111.         yield return new WaitForSeconds (timeToPlaceInHands);
    112.  
    113.         currentlyHeldItem = itemTransform; //Which item will be in hands
    114.         currentlyHeldItem.gameObject.SetActive (true); //Activating the item of interest, to show it in the players hands
    115.     }
    116. }
    117.  
     
  42. Deleted User

    Deleted User

    Guest

    That is my inventory script! for people to take a look at to see if you can spot any issues?
     
  43. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Sounds like you Item_Pickup script is wrong and not disabling the picked up item
     
  44. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    That's the old GUI code. Search for how to change text colour legacy GUI. Heaps of information
     
  45. Deleted User

    Deleted User

    Guest

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Item_Pickup : MonoBehaviour {
    5.  
    6.     private Item_Master itemMaster;
    7.  
    8.     void OnEnable()
    9.     {
    10.         SetInitialReferences ();
    11.         itemMaster.EventPickupAction += CarryOutPickupActions;
    12.     }
    13.  
    14.     void OnDisable()
    15.     {
    16.         itemMaster.EventPickupAction -= CarryOutPickupActions;
    17.     }
    18.  
    19.     void SetInitialReferences()
    20.     {
    21.         itemMaster = GetComponent<Item_Master> ();
    22.     }
    23.  
    24.     void CarryOutPickupActions(Transform tParent)
    25.     {
    26.         transform.SetParent (tParent);
    27.         itemMaster.CallEventObjectPickup ();
    28.         transform.gameObject.SetActive (false);
    29.     }
    30. }
    31.  
     
  46. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Check that the CarryOutPickupActions method is getting called
     
  47. Deleted User

    Deleted User

    Guest

    Just put a debug.log inside the CarryOutPickupActions method and it's coming up in the console haha, don't have a clue where I have gone wrong :/
     
  48. Deleted User

    Deleted User

    Guest

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Item_Master : MonoBehaviour {
    5.  
    6.     private Player_Master playerMaster;
    7.  
    8.     public delegate void GeneralEventHandler();
    9.     public event GeneralEventHandler EventObjectThrow;
    10.     public event GeneralEventHandler EventObjectPickup;
    11.  
    12.     public delegate void PickupActionEventHandler (Transform item);
    13.     public event PickupActionEventHandler EventPickupAction;
    14.  
    15.     void OnEnable()
    16.     {
    17.         //SetInitialReferences ();
    18.     }
    19.  
    20.     void Start()
    21.     {
    22.         SetInitialReferences ();
    23.     }
    24.  
    25.     public void CallEventObjectThrow()
    26.     {
    27.         if (EventObjectThrow != null)
    28.         {
    29.             EventObjectThrow (); //Throws object (Method)
    30.         }
    31.         playerMaster.CallEventHandsEmpty (); //Empty player hand (Method)
    32.         playerMaster.CallEventInventoryChanged (); //Changes Inventory (Method)
    33.     }
    34.  
    35.     public void CallEventObjectPickup()
    36.     {
    37.         if (EventObjectPickup != null)
    38.         {
    39.             EventObjectPickup (); //Pick up object method is run
    40.         }
    41.  
    42.         playerMaster.CallEventInventoryChanged (); //Implements the change in the inventory via the method shown
    43.     }
    44.  
    45.     public void CallEventPickupAction(Transform item)
    46.     {
    47.         if (EventPickupAction != null)
    48.         {
    49.             EventPickupAction (item);
    50.         }
    51.     }
    52.  
    53.     void SetInitialReferences()
    54.     {
    55.         if (GameManager_References._player != null)
    56.         {
    57.             playerMaster = GameManager_References._player.GetComponent<Player_Master> ();
    58.         }
    59.     }
    60. }
    61.  
     
  49. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    436
    Your subscriptions are wrong line 30 and 37
     
  50. crifab93

    crifab93

    Joined:
    Mar 29, 2016
    Posts:
    1
    Hi, I'm new, my name's Cristian, please to meet you all.

    Here's my first Assignment, I hope to have done it well :)