Search Unity

Third person cover controller

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

  1. studentvz

    studentvz

    Joined:
    Dec 14, 2014
    Posts:
    149
    I have managed to pinpoint the problem with frame debugger and also to solve it.

    // Required for the explosion preview.
    _camera.depthTextureMode = DepthTextureMode.Depth;

    What is explosion preview? What impact will it have on the rest of the asset if I remove this code?
     
  2. Alexey1B

    Alexey1B

    Joined:
    May 15, 2017
    Posts:
    26
    _camera.depthTextureMode = DepthTextureMode.Depth; - looks like used for shader of sphere material which visualize droped granade explosion radius, so should not affect something else
     
    studentvz likes this.
  3. studentvz

    studentvz

    Joined:
    Dec 14, 2014
    Posts:
    149
    Does anyone know how to make AI attack other objects? Where can I change/define a new target?

    For example, my Character/Player enters Vehicle and gets deactivated. How can AI attack vehicle? Now AI only walks/Investigates till the latest known position of Player and stops all activity.

    Also, how can I make AI vulnerable to the vehicle, for example, one hit with a vehicle will kill AI. At this moment, AI and Vehicle collide like any other static object.
     
    GWStudio likes this.
  4. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    324
    DepthTextureMode.Depth is needed for the shadows the pack or the scrip have nothing to do with it .
     
  5. Tempored_Insanity_Studio

    Tempored_Insanity_Studio

    Joined:
    Mar 4, 2013
    Posts:
    1
    Hi.
    Does anyone know how I could disable all gun functionality while a bool value is false, set from an external script? I'm trying to make a method to easily disable all gun and camera functionality (including switching weapon) when certain menus are open, etc. I'd guess it's in CharacterMotor somewhere, but I can't work out where to add code that would allow what I want.
     
  6. studentvz

    studentvz

    Joined:
    Dec 14, 2014
    Posts:
    149
    I provided clear evidence that the script is causing almost double "stats", and code that enables DepthTextureMode.Depth is in the same script.

    I'm shocked that no one noticed this before.
     
  7. Rahd

    Rahd

    Joined:
    May 30, 2014
    Posts:
    324
    it's kinds common knowledge ...
    https://forum.unity.com/threads/dir...even-with-no-shadow-casters-receivers.581632/
    https://forum.unity.com/threads/poor-performance-of-updatedepthtexture-why-is-it-even-needed.197455/
    more on this : https://catlikecoding.com/unity/tutorials/rendering/part-7/
     
    Last edited: Aug 28, 2019
  8. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    335
    Playing with the TPCS beta. Anybody figured out how to recentrer and resize the AI Graph Node ? ( it’s always a bit offset on top right corner)
     
  9. studentvz

    studentvz

    Joined:
    Dec 14, 2014
    Posts:
    149
    I place my character and zombieguy AI into the scene. Zombie just walks to and follows my character but does not attack. Why?
    SOLUTION: In 2017.4.30f1 layers are messed-up, you need to create and assign layers to characters.

    I create a new AI with a new character model. When I hit Play my AI is stuck in the floor. how to solve this?
     

    Attached Files:

    Last edited: Sep 8, 2019
  10. Camelot63RU

    Camelot63RU

    Joined:
    Jul 20, 2014
    Posts:
    17
    keep waiting beta on email
     
  11. jwsntn170

    jwsntn170

    Joined:
    Jun 17, 2017
    Posts:
    4
    Same here. Sent my request in mid-August. I believe he's taking a little bit of time off for his new kid.
     
  12. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    hey everyone, i have trouble with basegun script. The bullet hit trigger collider and i can't find how to change the code to add a "QueryTriggerInteraction.Ignore" into it. Disabling trigger on project level is not an option. Maybe im looking at the wrong script ?
     
  13. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Playing with the Beta, I'm pretty happy. Just I noticed when i started working on my new project in earnest...HitEffect script.

    CharacterEffects.cs does not take into account the normal of the surface that it strikes. Has anyone already solved this? I'd like to avoid using Raycasts to detect the direction of the needed normal...but I might just have to suck it up.

    I know: Instantiate(Hit, hit.Position); also: Instantiate(BigHit, hit.Position); is where this is happening and i know i just need to add a few parameters and bam it be fixed. Just wondering if anyone else has already fixed this particular annoyance. Solving this means i won't have to manually edit any of my particle effects.

    **edit, thats not the actual problem. It seems like the objects I'm using have multiple children...and its ONLY setting the rotation of the parent object...it may not even be doing that, since its set as billboard....argh this is confusing and frustrating

    Ok! Got to the bottom of the issue with HitEffects.
    in the OnHit function change it from this:
    Code (CSharp):
    1.         public void OnHit(Hit hit)
    2.         {
    3.             var prefab = hit.IsMelee ? Melee : Bullet;
    4.  
    5.             if (prefab == null)
    6.                 return;
    7.  
    8.             var effect = GameObject.Instantiate(prefab);
    9.             effect.transform.SetParent(null);
    10.             effect.transform.position = hit.Position + hit.Normal * 0.1f;
    11.             effect.SetActive(true);
    12.             GameObject.Destroy(effect, 4);
    13.         }
    To this instead:
    Code (CSharp):
    1.         public void OnHit(Hit hit)
    2.         {
    3.             var prefab = hit.IsMelee ? Melee : Bullet;
    4.  
    5.             if (prefab == null)
    6.                 return;
    7.  
    8.             var effect = GameObject.Instantiate(prefab);
    9.             effect.transform.SetParent(null);
    10.             effect.transform.position = hit.Position + hit.Normal * 0.1f;
    11. //below is the added line, there was no rotational math actually applied before, just positional
    12.             effect.transform.rotation = Quaternion.LookRotation( 0.75f * hit.Normal );
    13.             effect.SetActive(true);
    14.             GameObject.Destroy(effect, 4);
    15.         }
    Im finding that if you want blood spatter and impact effects to look correct don't use the script CharacterEffects for that. That will work fine with Sounds just fine, but not with spawning Particles Systems to show damage feedback. Later on I'll add a Randomizer to the .75f to add a little bit of variety to the rotation.
     
    Last edited: Sep 8, 2019
  14. SarhanSoft

    SarhanSoft

    Joined:
    Apr 15, 2015
    Posts:
    65
    your ask not clear!
     
  15. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Heres a question, with the legacy AI. What variable can i monitor to determine the AI's interest in the player? I want to make a dynamic music system that will ramp up music based on how many AI's are aware and Attacking or Investigating the presence of the player. IM having troubloe finding the correct value in the brain. Anyone have any idea? I originally tried to use the _isSearching as a int to be detected...but if the AI has multiple locations set then the counter goes up more than once. I don't mind making my own value for this, but I still need to know the specific variable to look up for a combat AI vs a Searching one.
     
  16. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Agreed, @dnaster is not clear what you are asking at all. Are you asking how to many the AI shoot things other than each other and the player? or something else entirely
     
  17. SarhanSoft

    SarhanSoft

    Joined:
    Apr 15, 2015
    Posts:
    65
    hmmm, i think this system will work with human only, not machine (helicopter)!
    and it is ready to use (player vs ai)
    ai will shoot player, as long as they are enemies. check the defualt/demo scene. and just copy scripts to your model
     
  18. SarhanSoft

    SarhanSoft

    Joined:
    Apr 15, 2015
    Posts:
    65
    try to check the fighter barin, State Struct, I use it to change the enemy start state, but im not sure if it changed with enemy state also. check it (if it changed with current enemy state or not) and maybe will help to solve your problem to calculate ai's in specific state.
     
  19. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    That was perfect! Thank you.
    Seems I just need to monitor if (IsAlerted) and (_isCombatProcess) I'll give it a few runs and find out if it works or not.
     
    SarhanSoft likes this.
  20. chakiry80

    chakiry80

    Joined:
    Oct 2, 2017
    Posts:
    8
    Hi Everyone , i imported the TPSC Latest version to Unity , But i have a Problem which is the layers , tags and inputs are not setup !
    Can anyone help me with that Please !
     
  21. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    If you want to despawn your AIs after death add this to CharacterHealth.cs

    add these 3 variables at the top:
    Code (CSharp):
    1.         private float currentDeadTimerElapsed = 0f;
    2.         private float despawnTime = 30f;
    3.         public bool wantDespawn = true;
    Add this to LateUpdate():
    DeadCounter();

    and finally the function where the magic happens add to the bottom:

    Code (CSharp):
    1.         /// <summary>
    2.         /// Starts a counter when the Agent Dies, then checks if its visible if its above the counter and out of camera view, destroy.
    3.         /// </summary>
    4.         private void DeadCounter()
    5.         {
    6.             if ((_isDead) && (wantDespawn))
    7.             {
    8.                 currentDeadTimerElapsed += Time.deltaTime;
    9.                 if ((currentDeadTimerElapsed >= despawnTime))
    10.                 {
    11.                     if (GetComponentInChildren<SkinnedMeshRenderer>().isVisible)
    12.                     {
    13.                         return;
    14.                     }
    15.                     else
    16.                     {
    17.                         Destroy(gameObject);
    18.                     }
    19.                 }
    20.             }
    21.         }
     
    Last edited: Sep 15, 2019
    Lay84 likes this.
  22. studentvz

    studentvz

    Joined:
    Dec 14, 2014
    Posts:
    149
    You have one example scene where there are allies that fight for you. Examine it, Actor component needs to have the same id and allies have a script that makes them follow you.
     
  23. jwsntn170

    jwsntn170

    Joined:
    Jun 17, 2017
    Posts:
    4
    Anybody tried using UMA 2 characters with this? I'm trying in the Top Down example scene but I keep gett this error:
    NullReferenceException: Object reference not set to an instance of an object
    CoverShooter.CharacterIK.Setup (CoverShooter.CharacterMotor motor) (at Assets/ThirdPersonCoverShooter/Scripts/Character/CharacterIK.cs:230)
    CoverShooter.CharacterMotor.Awake () (at Assets/ThirdPersonCoverShooter/Scripts/Character/CharacterMotor.cs:3145)
     
  24. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    I have just the thing for you! Give me a few minutes and I'll dig it out.

    *edit:

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

    Use this.
    In general this basically starts a timer when they die. And then the next step is, if the timer is greater than Despawn Time then next time they leave the camera they destroy the object (Enemy AI)
    I set it up so that you can add this to the general script. Then all you need is make sure Wants to Despawn is checked. and if it is then they can despawn, otherwise it behaves exactly the same way.
     
    Last edited: Sep 18, 2019
    Lay84 likes this.
  25. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    @dnaster What I've posted you, will do exactly what you want. Just change despawn time to 0.0f instead of 30.0f
     
    Last edited: Sep 19, 2019
  26. Lay84

    Lay84

    Joined:
    Mar 8, 2014
    Posts:
    34
    I'm thinking of restructuring the shooting mechanics on my mobile project. instead of aiming with touch stick, I'm thinking of simplifing it to a tap to shoot button that targets nearest enemy, then a tab button to switch to next closest. Havn't started yet buy wanted to get some thoughts approach as it pertains to TPCS. thanks in advance
     
  27. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    I'm not sure what you are having trouble with? What was your error exactly?
    Below
    Code (CSharp):
    1.     public class CharacterHealth : MonoBehaviour, ICharacterHealthListener
    2.     {
    on line 13th thru 15th
    Code (CSharp):
    1.         private float currentDeadTimerElapsed = 0f;
    2.         private float despawnTime = 30f;
    3.         public bool _wantDespawn = true;
    Right above

    public float Health = 100f;


    This is what your LateUpdate should look like on 115:

    Code (CSharp):
    1.         private void LateUpdate()
    2.         {
    3.             if (!_isDead)
    4.             {
    5.                 Health = Mathf.Clamp(Health + Regeneration * Time.deltaTime, 0, MaxHealth);
    6.                 check();
    7.             }
    8.             DeadCounter();
    9.         }

    I added Deadcounter() to line 199
    Code (CSharp):
    1. /// <summary>
    2.         /// if _wantDespawn is checked, Starts a counter when the Agent Dies, then checks if its visible if its above the counter and out of camera view, destroy.
    3.         /// </summary>
    4.         private void DeadCounter()
    5.         {
    6.             if ((_isDead) && (_wantDespawn))
    7.             {
    8.                 currentDeadTimerElapsed += Time.deltaTime;
    9.                 if ((currentDeadTimerElapsed >= despawnTime))
    10.                 {
    11.                     if (GetComponentInChildren<SkinnedMeshRenderer>().isVisible)
    12.                     {
    13.                         return;
    14.                     }
    15.                     else
    16.                     {
    17.                         Destroy(gameObject);
    18.                     }
    19.                 }
    20.             }
    21.         }
     
  28. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    I made default 30f change it to like 0f if you want instant. It's a public value so you can change it right there. Or do it in code w/e works for you.
     
  29. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    "inspector/Script " both? or just one? Needs to be in both. Worst case scenario you dont mind jankiness on despawning then just change then entire Dead counter function to this instead:

    Code (CSharp):
    1. private void DeadCounter()
    2.         {
    3.             if ((_isDead) && (_wantDespawn))
    4.             {
    5.                 currentDeadTimerElapsed += Time.deltaTime;
    6.                 if ((currentDeadTimerElapsed >= despawnTime))
    7.                 {
    8.                         Destroy(gameObject);
    9.                 }
    10.             }
    11.         }
    I gave you a elegant solution so they would despawn only if they were not on screen but, if thats not what you want do this instead. If this doesn't work for you, then gl. :)
     
  30. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Dnaster, I'm just curious here.
    So please do not take any offense, none is intended.
    I became curious by the questions you've been asking, so I checked a few posts in other threads.

    How familiar are you with programming and the engine itself?
    For example despawning GameObjects and Switching out animations seems pretty basic stuff. I can point you to some good teachers for Unity and C# if you want it.

    I just don't want to see you get frustrated with this asset and Engine because no one is answering your questions.

    [Sorry for posting this here, it would not let me start a private conversation with you, I believe due to some privacy setting you have]
     
  31. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Current Progress with Aura 2 and ATG (Advanced Terrain Grass) using Deferred Rendering


    Here is it with:
    Aura 2 and ATG and Beatify \ Highlight Pus
     
    Rahd likes this.
  32. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Sure np!
    Here's a channel I follow pretty good [Unity3d College ]:
    https://www.youtube.com/channel/UCX_b3NNQN5bzExm-22-NVVg
    Also we can't forget Penny [Holistic3d]:
    https://www.youtube.com/channel/UCp_SOgsRYdLfIEWLjM62ZJg
    I'll come back later to see if I can help you with that task.
     
  33. junrill

    junrill

    Joined:
    Jul 27, 2016
    Posts:
    8
    For those looking for Emerald Ai 2.0 integration

    on EmeraldAIPlayerDamage.cs

    Code (CSharp):
    1.         public void DamagePlayer(int DamageAmount) {
    2.  
    3.          float Damage = DamageAmount;
    4.         Vector3 normal = Vector3.zero;
    5.         float DamageResponseWaitTime = 0.3f;
    6.  
    7.         var hit = new Hit(GetComponent<Collider>().ClosestPointOnBounds(transform.position), normal, Damage, GetComponent<GameObject>(), GetComponent<GameObject>(), HitType.Fist, DamageResponseWaitTime);
    8.  
    9.             if (GetComponent<CoverShooter.CharacterHealth>() != null) {
    10.              
    11.                 SendMessage("OnHit", hit, SendMessageOptions.DontRequireReceiver);
    12.             }
    13.  
    14.         }
    and
    Code (CSharp):
    1.         public void SendPlayerDamage(int DamageAmount, Transform Target, EmeraldAISystem EmeraldComponent)
    2.         {
    3.             DamagePlayer(DamageAmount);
    4.         }
    Also, share if you have better integration.

    Thanks
     
  34. Anhella

    Anhella

    Joined:
    Nov 18, 2013
    Posts:
    67
    good day
    Is there any other unity Ai asset other than Emerald Ai 2.0 that could be integrated with TPSC?
    Thanks In Advance
     
  35. SarhanSoft

    SarhanSoft

    Joined:
    Apr 15, 2015
    Posts:
    65
    Hi EduardasFunka, you have long time no talk with us, is everything ok?I just enthusiastic for new version. good luck
     
  36. rmorph

    rmorph

    Joined:
    Apr 3, 2012
    Posts:
    87
    Hi! I wonder if any thought has been given to vehicle integration with this package? For example like in fortnight the ability to step in and out of a car or mount a turret on the back?

    I love the feature set 3PCC has but I also need to control vehicles - including big spaceships. I'm not sure how realistic it is to expect 3PCC to do that but ideally I would like a single controller system handling multiple states, rather than trying to juggle many different types of controllers and swapping between them, and I figured that if 3PCC integrated a vehicle system it would get me very close to what I needed.


    I would like to describe what I need and see if it makes sense - and I understand that since 3PCC is a person controller it probably can't do the vehicle movements and such - but I would like it to be the brain behind the vehicle cameras so that I have as little clutter as possible with multiple control systems.


    So.. is it possible to use 3PCC controller as a master for the following camera settings?

    Firstly I need (1) a great 3rd person controller, preconfigured with animations for as much as possible of modern AAA features such as climbing, aiming, ducking for cover etc. I would like to be able to integrate this with my character models pretty easily. This is the default character view and 3PCC looks perfect for the job.

    Secondly, I need a wide variety of vehicle support: close follow cams for vehicles such as (2) hoverbikes and then various spaceships from single-seat fighters (3) cockpit and (4) follow-cam all the way up to massive spaceships.

    If you've ever played dreadnought you know what I'm talking about: The ability to zoom in and out to immense distance with a (5) lazy follow-cam, and the ability to switch to various views: (6) satellite orbit, (7) turret cam etc as well as an (8) ship bridge view (inside). I assume these are multiple predefined cameras - and to be honest I think your top-down asset comes kind of close to that if I understand it right?

    Ideally, these views are swappable by hotkey.. in or out of the vehicle and which vehicle - large or small - and the controller will detect what views are relevant to which character state to provide the correct camera and control system.

    I understand this is a big ask so I appreciate your thoughts on whether this is doable, or how best I could close with this kit and for example integration with other products?
     
  37. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    He's fine. He is on paternity leave. I'm sure he will have lots to say once he gets back.
     
    SarhanSoft likes this.
  38. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    The vehicles are doable. There are several folks that have already managed that. Read some of the past messages to find out how to manage it.
     
  39. rmorph

    rmorph

    Joined:
    Apr 3, 2012
    Posts:
    87
    That's awesome. I'm on like page 17 :D
     
  40. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Sorry I wasn't at a PC to give you the more perma link thingy but the stuffs there! Gl with your implementation.
     
  41. p_hergott

    p_hergott

    Joined:
    May 7, 2018
    Posts:
    414
    Whens the update?
     
  42. rmorph

    rmorph

    Joined:
    Apr 3, 2012
    Posts:
    87
    No worries - I took a leap of faith and bought the asset. Going through the forum history shows me there's a great community effort to get the most from it.

    I will get my characters imported and then I hope I can call on you guys to give me a bit of assistance with vehicles. I see you made an effort made to integrate with Cinemachine... I was thinking that might be an option for all the vehicle side of things... especially a dreadnought style spaceship controller.

    Also great stuff with the drones! I would love to know how you did that if thats OK?
     
  43. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Sure, I'll put together what I hope is a basic explanation of how I did the drone, it was rough work pulling those strings into a cohesive bunch. I never did get Cinimachine working though unfortunately. The next few posts are how I configured all of this.

    Do me a favor though since i used this Youtube channel to figure this all out, its literally his drone code:


    Its free so I don't think he would really mind, but at least give him a watch even if you don't pay attention. He still deserves the views.
    He also has links to audio and models.

    First you need 2 Transforms attached to your character.
    No scripts attached to them, its just for Positional Placement. Id name them something like:
    DroneSpawnPoint
    DroneCameraSpawnPoint

    Here's the hard bit, I did this a while ago. But i did make this one master script, and I altered ThirdPersonInput a smidge. I'm not sure how good your coding is but this is my script for the activation, so some edits will be needed for you to make it work, such as pulling out the parts specifically for my menus like
    public GameObject PauseCanvas;
    public GameObject MenuCanvas;

    These are unique to me and unless you set something up your self those parts wont work for you, if you chose to leave those parts in that's fine, there's no functions you are missing out on and its all set up script side already you just need to make your own menus. It should be fairly obvious what to leave out if you extract them. just remember to check each script for referances to them.
    :
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using CoverShooter;
    5.  
    6. public class MenuPlayer : MonoBehaviour
    7. {
    8.  
    9.     public bool Paused = false;
    10.     public bool Menu = false;
    11.     public bool DroneCameraOn = false;
    12.     public ThirdPersonInput Player;
    13.     public GameObject PauseCanvas;
    14.     public GameObject MenuCanvas;
    15.     public Camera PlayerCamera;
    16.     public GameObject DroneCamera;
    17.     public GameObject DroneSet;
    18.     public Transform DroneSpawnPoint;
    19.     public Transform DroneCameraSpawnPoint;
    20.     private GameObject DroneCameraGO;
    21.     private GameObject DroneObjectGO;
    22.     public string DroneCameraTag = "DroneCamera";
    23.     public string DroneObjectTag = "PlayerDrone";
    24.  
    25.     // Use this for initialization
    26.     void Start()
    27.     {
    28.         Paused = false;
    29.         Menu = false;
    30.         DroneCameraOn = false;
    31.         PauseCanvas.gameObject.SetActive(false);
    32.         MenuCanvas.gameObject.SetActive(false);
    33.         PlayerCamera.gameObject.SetActive(true);
    34.     }
    35.  
    36.     // Update is called once per frame
    37.     public void LateUpdate()
    38.     {
    39.         if (Input.GetKeyDown(KeyCode.P))
    40.         {
    41.             Pause();
    42.         }
    43.         if (Input.GetKeyDown(KeyCode.U))
    44.         {
    45.             MenuScreen();
    46.         }
    47.         if (Input.GetKeyDown(KeyCode.O))
    48.         {
    49.             DroneActivation();
    50.         }
    51.     }
    52.  
    53.     void Pause()
    54.     {
    55.         if ((Paused != true) && (Menu != true)) //|| (DroneCameraOn != false))
    56.         {
    57.             PausedOn();
    58.         }
    59.         else
    60.         {
    61.             PausedOff();
    62.         }
    63.     }
    64.  
    65.     void MenuScreen()
    66.     {
    67.         if ((Menu != true) && (Paused != true)  && (DroneCameraOn != true))
    68.         {
    69.             TurnOnMenu();
    70.         }
    71.         else
    72.         {
    73.             TurnOffMenu();
    74.         }
    75.     }
    76.  
    77.     private void PausedOn()
    78.     {
    79.         PauseCanvas.gameObject.SetActive(true);
    80.         Time.timeScale = .000001f;
    81.         Player.isPause = !Player.isPause;
    82.         Paused = !Paused;
    83.     }
    84.  
    85.     private void PausedOff()
    86.     {
    87.         PauseCanvas.gameObject.SetActive(false);
    88.         Time.timeScale = 1;
    89.         Player.isPause = !Player.isPause;
    90.         Paused = !Paused;
    91.     }
    92.  
    93.     public void TurnOnMenu()
    94.     {
    95.         MenuCanvas.gameObject.SetActive(true);
    96.         Menu = true;
    97.         Player.isPause = !Player.isPause;
    98.         Player.isMenu = !Player.isMenu;
    99.     }
    100.  
    101.     public void TurnOffMenu()
    102.     {
    103.         MenuCanvas.gameObject.SetActive(false);
    104.         Menu = false;
    105.         Player.isPause = !Player.isPause;
    106.         Player.isMenu = !Player.isMenu;
    107.     }
    108.  
    109.     public void DroneActivation()
    110.     {
    111.         if (DroneCameraOn == false)
    112.         {
    113.             Player.isPause = !Player.isPause;
    114.             DroneCameraOn = !DroneCameraOn;
    115.             DroneInstantiation();
    116.         }
    117.         else
    118.         {
    119.             Player.isPause = !Player.isPause;
    120.             DroneCameraOn = !DroneCameraOn;
    121.             PauseCanvas.gameObject.SetActive(false);
    122.             DroneCameraGO.gameObject.SetActive(false);
    123.             DestroyDroneStuff();
    124.         }
    125.     }
    126.  
    127.     public void DroneInstantiation()
    128.     {
    129.         Instantiate(DroneCamera, DroneCameraSpawnPoint.position, DroneCameraSpawnPoint.rotation);
    130.         Instantiate(DroneSet, DroneSpawnPoint.position, DroneSpawnPoint.rotation);
    131.         FindDroneStuff();
    132.     }
    133.  
    134.     public void FindDroneStuff()
    135.     {
    136.         DroneCameraGO = GameObject.FindWithTag(DroneCameraTag);
    137.         DroneObjectGO = GameObject.FindWithTag(DroneObjectTag);
    138.         DroneOnCameraStates();
    139.     }
    140.  
    141.     public void DroneOnCameraStates()
    142.     {
    143.         PlayerCamera.gameObject.SetActive(false);
    144.         DroneCameraGO.gameObject.SetActive(true);
    145.     }
    146.  
    147.     public void DestroyDroneStuff()
    148.     {
    149.         Destroy(DroneCameraGO);
    150.         Destroy(DroneObjectGO);
    151.         PlayerCamera.gameObject.SetActive(true);
    152.     }
    153. }
    I added this to ThirdPersonInput:
    Code (CSharp):
    1.         #region Custom Settings
    2.         /// <summary>
    3.         /// Player_Goes_Here
    4.         /// </summary>
    5.         public MenuPlayer menu_Player;
    6.  
    7.         /// <summary>
    8.         /// Pauses the Game
    9.         /// </summary>
    10.         public bool isPause = false;
    11.  
    12.         /// <summary>
    13.         /// Pauses the game when your in a menu
    14.         /// </summary>
    15.         public bool isMenu = false;
    16.  
    17.         /// <summary>
    18.         /// Bool to control if you have control over a drone
    19.         /// </summary>
    20.         public bool isDroneCamera = false;
    21.  
    22.         #endregion
    As well as this:
    Code (CSharp):
    1.         void CheckMenuPlayer()
    2.         {
    3.             isPause = menu_Player.Paused;
    4.             isMenu = menu_Player.Menu;
    5.  
    6.         }
    And finally added this to the update method of the same script:
    Code (CSharp):
    1. CheckMenuPlayer();
    I also had to alter the first like where is says (Disabler != null && Disabler.activeself) return; this this instead:

    Code (CSharp):
    1.  if (Disabler != null && Disabler.activeSelf || isPause == true || isMenu == true || isDroneCamera == true)
    2.                 return;
     
    Last edited: Oct 2, 2019
    rmorph likes this.
  44. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Here is Pt 2 of the Drone bit. In the last post we altered the player scripts, now we code the drone:
    Make a new script and call it DroneCameraFollow
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DroneCameraFollow : MonoBehaviour
    6. {
    7.     private Transform ourDrone;
    8.     public string droneTag = "PlayerDrone";
    9.     public float DampingTime = 0.3f;
    10.  
    11.     void Start()
    12.     {
    13.         ourDrone = GameObject.FindGameObjectWithTag(droneTag).transform;
    14.     }
    15.  
    16.     private Vector3 velocityCameraFollow;
    17.     public Vector3 behindPosition = new Vector3(0, 2, -4);
    18.     public float angle;
    19.  
    20.     void FixedUpdate()
    21.     {
    22.         transform.position = Vector3.SmoothDamp(transform.position, ourDrone.transform.TransformPoint(behindPosition) + Vector3.up *Input.GetAxis("Vertical"), ref velocityCameraFollow, DampingTime);
    23.         transform.rotation = Quaternion.Euler(new Vector3(angle, ourDrone.GetComponent<DroneMovementScript>().currentYRotation, 0));
    24.     }
    25. }
    26.  
    You are gonna put that on a Camera.
    Set your inspector to my values then save as a prefab:


    For the Drone itself we have a few parts. You can just grab a free QuadCopter Mesh off the asset store. Its best if you get one where the propellers are separate objects.
    here is how I have my organized in the Hierachy:

    1. Make an empty Game Object name it Drone Parent (essentially we just want a container)
    2. drone_sound is also just a Gameobject with nothing except a AudioSource, put your propellor sound on that and set it to Play on Awake and Loop - set to 3d sound
    Select DroneParent
    Make another new script we're almost there I promise, call it: DroneMovementScript

    Fill it in with this:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5.  
    6. public class DroneMovementScript : MonoBehaviour
    7. {
    8.     Rigidbody ourDrone;
    9.  
    10.     #region Variables
    11.     public float MaxTiltAngle = 20f;
    12.     public float ForwardDamping = 0.1f;
    13.     public float StrafeDamping = 0.1f;
    14.     public float RotationDamping = 0.25f;
    15.     public float DampToZero = 0.45f;
    16.     public float DroneSoundVolume = 0.045f;
    17.  
    18.     //Forces
    19.     [HideInInspector] public float upForce;
    20.     private Vector3 velocityToSmoothDamptoZero;
    21.  
    22.     //Movement Front \ Back
    23.     private float movementForwardSpeed = 500.0f;
    24.     private float tiltAmountForward = 0f;
    25.     private float tiltVelocityForward; //
    26.  
    27.     //Movement Strafe
    28.     private float sideMovementAmount = 300f;
    29.     private float tiltAmountSideways;
    30.     private float tiltAmountVelocity;
    31.  
    32.     //Rotation
    33.     private float wantedYRotation;
    34.     [HideInInspector] public float currentYRotation;
    35.     private float rotateAmountByKeys = 1.5f;
    36.     private float rotationYVelocity;
    37.  
    38.     //Audio
    39.     private AudioSource dronesound;
    40.  
    41.     #endregion
    42.  
    43.  
    44.     void Awake()
    45.     {
    46.         ourDrone = GetComponent<Rigidbody>();
    47.         dronesound = gameObject.transform.Find("drone_sound").GetComponent<AudioSource>();
    48.     }
    49.  
    50.     void FixedUpdate()
    51.     {
    52.         MovementUpDown();
    53.         MovementForward();
    54.         Rotation();
    55.         ClampingSpeedValues();
    56.         Strafe();
    57.         DroneSound();
    58.  
    59.         ourDrone.AddRelativeForce(Vector3.up * upForce);
    60.         ourDrone.rotation = Quaternion.Euler(new Vector3(tiltAmountForward, currentYRotation, tiltAmountSideways));
    61.     }
    62.  
    63.     #region UpDownPull
    64.  
    65.     void MovementUpDown()
    66.     {
    67.         if ((Mathf.Abs(Input.GetAxis("Vertical")) > 0.2f || Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f))
    68.         {
    69.             if (Input.GetKey(KeyCode.I) || (Input.GetKey(KeyCode.K)))
    70.             {
    71.                 ourDrone.velocity = ourDrone.velocity;
    72.             }
    73.             if (!Input.GetKey(KeyCode.I) && !Input.GetKey(KeyCode.K) && !Input.GetKey(KeyCode.J) && !Input.GetKey(KeyCode.L))
    74.             {
    75.                 ourDrone.velocity = new Vector3(ourDrone.velocity.x, Mathf.Lerp(ourDrone.velocity.y, 0, Time.deltaTime * 5), ourDrone.velocity.z);
    76.                 upForce = 281;
    77.             }
    78.             if (!Input.GetKey(KeyCode.I) && !Input.GetKey(KeyCode.K) && Input.GetKey(KeyCode.J) || Input.GetKey(KeyCode.L))
    79.             {
    80.                 ourDrone.velocity = new Vector3(ourDrone.velocity.x, Mathf.Lerp(ourDrone.velocity.y, 0, Time.deltaTime * 5), ourDrone.velocity.z);
    81.                 upForce = 110;
    82.             }
    83.             if(Input.GetKey(KeyCode.J) ||Input.GetKey(KeyCode.L))
    84.             {
    85.                 upForce = 410;
    86.             }
    87.         }
    88.  
    89.         if(Mathf.Abs(Input.GetAxis("Vertical")) < 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f)
    90.         {
    91.             upForce = 135;
    92.         }
    93.         if (Input.GetKey(KeyCode.I))
    94.         {
    95.             upForce = 450f;
    96.             if(Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f)
    97.             {
    98.                 upForce = 500;
    99.             }
    100.         }
    101.         else if (Input.GetKey(KeyCode.K))
    102.         {
    103.             upForce = -200f;
    104.         }
    105.         else if (!Input.GetKey(KeyCode.I) && !Input.GetKey(KeyCode.K) && Mathf.Abs(Input.GetAxis("Vertical")) <0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) < 0.2f)
    106.         {
    107.             upForce = 98.1f;
    108.         }
    109.     }
    110.  
    111.     #endregion
    112.  
    113.     #region directional_movement
    114.  
    115.  
    116.     void MovementForward()
    117.     {
    118.         if(Input.GetAxis("Vertical") !=0)
    119.         {
    120.             ourDrone.AddRelativeForce(Vector3.forward * Input.GetAxis("Vertical") * movementForwardSpeed);
    121.             tiltAmountForward = Mathf.SmoothDamp(tiltAmountForward, MaxTiltAngle * Input.GetAxis("Vertical"), ref tiltVelocityForward, ForwardDamping);
    122.         }
    123.     }
    124.     #endregion
    125.  
    126.     #region Rotation
    127.     void Rotation()
    128.     {
    129.         if(Input.GetKey(KeyCode.J))
    130.         {
    131.             wantedYRotation -= rotateAmountByKeys;
    132.         }
    133.         if(Input.GetKey(KeyCode.L))
    134.         {
    135.             wantedYRotation += rotateAmountByKeys;
    136.         }
    137.         currentYRotation = Mathf.SmoothDamp(currentYRotation, wantedYRotation, ref rotationYVelocity, RotationDamping);
    138.     }
    139.  
    140.     #endregion
    141.  
    142.     #region SpeedClamping
    143.     void ClampingSpeedValues()
    144.     {
    145.         if(Mathf.Abs(Input.GetAxis("Vertical")) > 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f)
    146.         {
    147.             ourDrone.velocity = Vector3.ClampMagnitude(ourDrone.velocity, Mathf.Lerp(ourDrone.velocity.magnitude, 10.0f, Time.deltaTime * 5f));
    148.         }
    149.         if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) < 0.2f)
    150.         {
    151.             ourDrone.velocity = Vector3.ClampMagnitude(ourDrone.velocity, Mathf.Lerp(ourDrone.velocity.magnitude, 10.0f, Time.deltaTime * 5f));
    152.         }
    153.         if (Mathf.Abs(Input.GetAxis("Vertical")) < 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f)
    154.         {
    155.             ourDrone.velocity = Vector3.ClampMagnitude(ourDrone.velocity, Mathf.Lerp(ourDrone.velocity.magnitude, 5.0f, Time.deltaTime * 5f));
    156.         }
    157.         if(Mathf.Abs(Input.GetAxis("Vertical")) < 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) <0.2f)
    158.         {
    159.             ourDrone.velocity = Vector3.SmoothDamp(ourDrone.velocity, Vector3.zero, ref velocityToSmoothDamptoZero, DampToZero);
    160.         }
    161.     }
    162.     #endregion
    163.  
    164.     #region Strafing
    165.     void Strafe()
    166.     {
    167.         if(Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f)
    168.         {
    169.             ourDrone.AddRelativeForce(Vector3.right * Input.GetAxis("Horizontal") * sideMovementAmount);
    170.             tiltAmountSideways = Mathf.SmoothDamp(tiltAmountSideways, -MaxTiltAngle * Input.GetAxis("Horizontal"), ref tiltAmountVelocity, StrafeDamping);
    171.         }
    172.         else
    173.         {
    174.             tiltAmountSideways = Mathf.SmoothDamp(tiltAmountSideways, 0, ref tiltAmountVelocity, StrafeDamping);
    175.         }
    176.     }
    177.     #endregion
    178.  
    179.     #region Audio
    180.     void DroneSound()
    181.     {
    182.         dronesound.pitch = 1 + (ourDrone.velocity.magnitude / 100);
    183.         dronesound.volume = 0.045f;
    184.     }
    185.     #endregion
    186. }
    187.  
    Place that script onto DroneParent and fill in with these values:

    And Finally! 1 last optional script:
    If you want spinning propellers add this one as well to your project, and attached to each propeller:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PropRotation : MonoBehaviour
    6. {
    7.     public float speed = 3000f; //degrees per second
    8.  
    9.     void Update()
    10.     {
    11.         transform.Rotate(Vector3.forward * Time.deltaTime * speed);
    12.     }
    13. }
    Make a prefab of your Drone Body to go with your Drone Camera now. And fill in the Slots on MenuPlayer located on your character like this:



    Player Camera is the normal camera you would be using by default.
    Drone Camera is obviously the Camera we setup for the drone
    Drone Set: This is the Main Drone Body and propellers we also set up
    Drone Spawn Point is the Transform we set up first I recommend putting this above and to the right of the player
    Drone Camera Spawn Point is the other Transform make sure this behind and above the player for best result.
    And finally the last 2 fields are the tags we will be looking for.

    If you chose to leave Pause canvas and Menu Canvas in the scripts just drag your Menus in the appropriate field.

    That's the best I can do at the moment. I might tighten these up in the next few days if i decide to put the drone in my new prototype, as this was fairly brute force. I'm sure you can find ways to optimize this.
    I hope this helped! Goodluck!
     
    Last edited: Oct 2, 2019
    rmorph likes this.
  45. rmorph

    rmorph

    Joined:
    Apr 3, 2012
    Posts:
    87
    Seriously amazing job Paul! Thanks so much for sharing that.
     
  46. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Np at all, if for what ever reason IMGR images won't show...jst use this link instead:
    https://paulswansonblog.wordpress.com/2019/10/02/tpc-redbee-drone/
    The images are here as well.
    It is definitely formatted better here, but if you need images they are there.

    Also your Interstellar Project looks like a neat project.
     
    Last edited: Oct 2, 2019
  47. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Just figured out why it wont subtract Shotgun ammunition
    It only subtracts if you have ReloadWithMagazines bool checked. I'll see if I can fix this throughout out the day.
    This makes sense why its only affecting shotguns, pretty much everything else would use magazines. I think if we write a new function then it'll be fine.

    This appears to be the culprit:
    in Basegun:

    Code (CSharp):
    1.             gun.NotifyPump();
    2.  
    3.             if (!gun.IsFullyLoaded && !gun.ReloadWithMagazines && gun.PumpAfterBulletLoad)
    4.             {
    5.                 _willReloadAfterPump = false;
    6.                 loadBullet();
    7.             }
    8.             else if (_willReloadAfterPump)
    9.             {
    10.                 _willReloadAfterPump = false;
    11.                 InputReload();
    12.             }
    13.         }
    Seems it only subtracts ammo if
    Gun is not Fully Loaded,
    ReloadwithMagazines = false
    PumpAfterBulletLoad = true

    So we need to build a new loop that essentially, checks if reload can be interrupted if it can then stop loop during fire \ or something else, and if it can't loop thru until gun is fully reloaded. It also needs to wait until the animation for each pump is complete before processing the next one. I'm open to ideas. Bc I don't know how to fix this
     
    Last edited: Oct 2, 2019
  48. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    Ok I Finally figured out how update Manager Works. The attach instructions are wretched so here is how they should really have been written.
    A) Set up your scene. Drag Assets -> UpdateManager -> Prefabs -> Update Manager into your scene.
    B) Open your script. Lets use this Assets CharacterMotor script.
    Change this:
    public class CharacterMotor : MonoBehaviour into this -> public class CharacterMotor : OverridableMonoBehaviour
    Find Awake
    And change its function name into this: protected override void Awake()
    Very First Line add this:
    base.Awake();

    In any script where you use Update, LateUpdate or Fixed Update change the function title to one of these:
    public override void UpdateMe()
    public override void FixedUpdateMe()
    public override void LateUpdateMe()

    This is all you have to do. Save it and try it.
    @Unplug
     
    Rahd likes this.
  49. Munken

    Munken

    Joined:
    Dec 28, 2013
    Posts:
    9
    HI Paul
    Thanks for sharing. I did as you described to the CharacterMotor script but now i can't get my camera to follow the player just sits at 0,0,0... i can see that there is some lateUpdate going on with the camera but i'm not sure how to change that?
     
  50. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    318
    It did the same thing to me until I added the prefab to my scene. Your problably seeing things in the console like keyword not added or something.So make sure you added update manager prefab

    This is the key I think you missed:
    Drag Assets -> UpdateManager -> Prefabs -> Update Manager into your scene.
     
    Last edited: Oct 3, 2019