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

Third Person Controller - Third Person, AI, Multiplayer, Mobile Framework

Discussion in 'Assets and Asset Store' started by opsive, Jan 21, 2015.

Thread Status:
Not open for further replies.
  1. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Instead of setting the count on the item monitor you can set it on the inventory and then the UI will also update:

    http://opsive.com/assets/ThirdPerso...entory.html#a3443270cfaa94f490b9f76f29447bef7
     
    BigRookGames likes this.
  2. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
  3. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Hello! How´s it going ? .. For me really great, but I got stuck on this recoil settings and animations.. See I tried to lower and raise the recoil settings alot but it looks all the same... and tried tampering wih the animations of the pistol but didnt happening anything... When you make the gun.. does the animation apply automaticly? The pistol idle is quite "Still" ? im a bit confused about this.
     
  4. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    The animations add the recoil so if you switch out the pistol animation you can add more or less recoil. The recoil setting that you are likely looking at refers to the UI crosshairs and how much of a spread is applied.
     
  5. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    aah I see :) okay yes, I probably looked at the one for the crossair. I tought it was like in ufps.
     
  6. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    hello @opsive

    I cant get my reload to work.. I have gun, it plays attack and idle animation... On the gun in Animator Options I filled in Idle, Attack, Reload.. The gun have 5 bullets.. the amount of bullets I have is 20.. i have assigned reload button.. Dosent work.. And it dont reload when the clip is empty neither... what have I missed? =)
     
    Roy927 likes this.
  7. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    This one is tough to say without taking a look at the code. What I would do is place a breakpoint within ItemHandler.TryReload and see where it returns early. If you tell me the line number that it returns early on I can explain the reasoning behind it.
     
  8. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Thanks I’ll do it later today!

    I dont know what debug I should use so I do both debug.break and VS place breakpoint.
     
    Last edited: Jul 16, 2018
  9. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    I dont know how to do that.. but I placed debug.log at if its a reloadable item, or if its not, and if it returns...
    when I hit "r" it logs that its a reloadable item, and same thing on controller, so it gets the message, and no error.. it just not simply reloads, no animation and no more bullets...??

    Thanks Justin =)
     
  10. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    So it's getting to IReloadableItem.TryStartReload which is good. Within ShootableWeapon.TryStartReload where does it return before getting to the "if (unloadedCount > 0)" branch? It is probably failing at one of these conditions:

    Code (csharp):
    1.  
    2.             // The weapon is already being reloaded so it cannot be reloaded again.
    3.             if (m_Reloading) {
    4.                 return false;
    5.             }
    6.  
    7.             // Can't reload if the clip size if infinitely large.
    8.             if (m_ClipSize == int.MaxValue) {
    9.                 return false;
    10.             }
    11.  
    12.             // Can't reload if the clip is full.
    13.             var loadedCount = m_Inventory.GetItemCount(m_ItemType, true);
    14.             if (loadedCount == m_ClipSize) {
    15.                 return false;
    16.             }
    17.  
    18.             // Ask the inventory how much ammo is remaining.
    19.             var unloadedCount = m_Inventory.GetItemCount(m_ItemType, false);
    20.             if (unloadedCount > 0) {
    21.  
     
  11. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
    Ran into an issue with character animation. I accidentally duplicated the entire player character and pushed play, exited and reran the scene and the animations no longer play on the original. If i duplicate it again and have the duplicate in the scene, the original one animates properly, but as soon as I remove the duplicate, the animations no longer work and I receive:

    NullReferenceException: Object reference not set to an instance of an object
    Opsive.ThirdPersonController.AnimatorMonitor.ChangeAnimatorStates (Int32 layer, System.String destinationState, Single transitionDuration, Boolean canReplay, Single speedMultiplier, Single normalizedTime) (at Assets/Third Person Controller/Scripts/Character/AnimatorMonitor.cs:608)
    Opsive.ThirdPersonController.AnimatorMonitor.DetermineState (Int32 layer, Opsive.ThirdPersonController.AnimatorStateData defaultState, Boolean checkAbilities, Boolean baseStart) (at Assets/Third Person Controller/Scripts/Character/AnimatorMonitor.cs:338)
    Opsive.ThirdPersonController.AnimatorMonitor.DetermineStates (Boolean checkAbilities) (at Assets/Third Person Controller/Scripts/Character/AnimatorMonitor.cs:270)
    Opsive.ThirdPersonController.AnimatorMonitor.DetermineStates () (at Assets/Third Person Controller/Scripts/Character/AnimatorMonitor.cs:256)
    Opsive.ThirdPersonController.RigidbodyCharacterController.set_Moving (Boolean value) (at Assets/Third Person Controller/Scripts/Character/RigidbodyCharacterController.cs:229)
    Opsive.ThirdPersonController.RigidbodyCharacterController.UpdateAnimator () (at Assets/Third Person Controller/Scripts/Character/RigidbodyCharacterController.cs:1109)
    Opsive.ThirdPersonController.RigidbodyCharacterController.Move (Single horizontalMovement, Single forwardMovement, Quaternion lookRotation) (at Assets/Third Person Controller/Scripts/Character/RigidbodyCharacterController.cs:494)
    Opsive.ThirdPersonController.ControllerHandler.FixedUpdate () (at Assets/Third Person Controller/Scripts/Character/ControllerHandler.cs:284)

    and looking at the animatorMonitor :608 I see that the m_ActiveStateHash is null.

    Any idea what link got messed up when duplicating?
     
    Last edited: Jul 17, 2018
  12. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Does AnimatorMonitor.PlayDefaultStates get called? The animator needs to be enabled for this method not to end early (and then initialize the hash array)
     
  13. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    It dosent go that far.. it cant get it to log on any of these.... Well.. I could just wait for tpc2 .. I can level design now instead :D
     
  14. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
    no it does not, in the start up code:
    Code (CSharp):
    1. public void Start()
    2.         {
    3.             if (GetComponent<Inventory>() == null) {
    4.                 Initialize();
    5.             }
    6.         }
    GetComponent<Inventory> is not null so it does not call initialize. Any idea what might have caused the change in this behavior?

    for now i commented out the if statement and it seems to work temporarily.
     
  15. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    If you have an inventory then Initialize is called after the default loadout has been loaded. It should be triggered from the OnInventoryInitialized event (registered within Awake of AnimatorMonitor).
     
  16. XOA_Productions

    XOA_Productions

    Joined:
    Nov 27, 2016
    Posts:
    24
    Hey there!

    I've got a small problem with MoveToTarget() in an ability I created. Most of the time it works perfectly fine, however, sometimes it will not align the character perfectly (I believe the rotation is off, the position still seems fine), resulting in my animations being misaligned. Are there any common things that I can check for that could cause this?
    The Ability I'm using is pretty similar to the included Ride ability. Could the issue be that the target position is underneath the terrain in certain scenarios and physics screws with the final position?
    (I'm not sure if it's physics related since it happens in the same spot that it usually works perfectly in, sometimes)
    Also, is MoveToTarget supposed to use animations while moving, or is it just supposed to just move the transform around (my character directly moves to the target position without any walk animation - not sure if this is supposed to happen)?

    Regards,
    Ben
     
  17. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    When it doesn't happen can you try setting a breakpoint within Ability.MoveToTargetLocal to see why the while loop isn't breaking? This should help indicate what is going wrong.

    The current version doesn't have any exposed settings and it does slide a lot. You can try manually adjusting the constants within MoveToTargetLocal to match your character better, but I ended up having to write a completely new ability for this in version 2 to get it working properly with the animation system.
     
  18. Daniel-Talis

    Daniel-Talis

    Joined:
    Dec 10, 2011
    Posts:
    425
    Hi, I'm exploring the demos and need to know how to initiate 'fly'.
     
  19. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    You can use the 'Z' key.
     
  20. Soul_Raven

    Soul_Raven

    Joined:
    Apr 12, 2014
    Posts:
    13
    I bought this asset a while back and I'm using it for a police sim I am working on.

    My first question is what on the character can I turn of so that the character is not in use while in a vehicle.

    And I am using it on unity 2018. When i go through the process of seting up a weapon and set the rotation values in the inspector after gameplay. On the next gameplay it would rotate the gun to the right again.
     
  21. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    You can send the OnAllowGameplayInput event: https://legacy.opsive.com/assets/ThirdPersonController/documentation.php?id=116

    Did you past the position/rotation after existing play mode? Beyond that make sure you are using the latest version of the controller - there was an issue in previous versions similar to this that was fixed.
     
  22. russnash37

    russnash37

    Joined:
    Feb 22, 2017
    Posts:
    31
    I'm having an issue with a NullReferenceException being generated at line 574 in AnimatorMonitor.cs, the m_ActiveStateHash[layer] statement appears to be what is generating it (the layer variable has the value 0):



    This is happening during every frame where the character either starts or stops walking.

    Thanks in advance for any assistance.

    Russ.
     
    Last edited: Aug 12, 2018
  23. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    How are you initializing the character? That error looks similar to this: https://forum.unity.com/threads/thi...-mobile-framework.292541/page-80#post-3566935
     
  24. russnash37

    russnash37

    Joined:
    Feb 22, 2017
    Posts:
    31
  25. Daniel-Talis

    Daniel-Talis

    Joined:
    Dec 10, 2011
    Posts:
    425
    I'm looking at this asset to use for an Adventure style game. A couple of questions..
    For the inventory system, can I use my own objects?
    Can a character use animations other than (and as well as) the ones supplied.. eg. point a finger, hold both arms up to the sky, point an object other than one that comes with the pack, etc?
     
  26. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    You shouldn't need to manually call it, but AnimatorMonitor.PlayDefaultStates needs to be called first for that array to be initialized. If you have an inventory component it is initialized from the OnInventoryInitialized event.
     
  27. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Thanks for taking a look at third person!

    Do you mean your own weapons, or something more generic? You can definitely use your own weapons, and if you want to create a new type of weapon that has properties not included then you can extend the Item class. In most cases you won't need to do this but it depends on exactly what you are trying to add.

    Yes. You can trigger small animations like that without having to code anything:

     
  28. hengin

    hengin

    Joined:
    Aug 13, 2018
    Posts:
    2
    when i input the invoice number to get the source code,the web page no responding,What should I do?(come from china)
     
  29. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    I think that I responded to your email. Make sure you've downloaded the Third Person Controller off of the Asset Store first.
     
  30. hengin

    hengin

    Joined:
    Aug 13, 2018
    Posts:
    2
    thank your reply,I haven't received the mail yet,Let me wait...or you can try to send the source code to this email:1282507214@qq.com , trouble you ;I'm sure i have downloaded the asset from U3D asset store.
     
  31. russnash37

    russnash37

    Joined:
    Feb 22, 2017
    Posts:
    31
    We are integrating with DevDog's Inventory Pro, so the normal inventory component in TPC is disabled.
     
  32. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Are you using the integration from the integrations page? Or your own? The Inventory Pro integration keeps the third person inventory active. If you are doing your own integration you'll need to send the OnInventoryInitialized event.
     
  33. russnash37

    russnash37

    Joined:
    Feb 22, 2017
    Posts:
    31
    We are using the integration from the integrations page.
     
  34. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    I just tested that integration and the TPC inventory stayed enabled. Can you tell me how to reproduce the error from the Inventory Pro sample scene?
     
  35. russnash37

    russnash37

    Joined:
    Feb 22, 2017
    Posts:
    31
    I'm wondering if one of my colleagues disabled the Inventory script from TPC, if I re-enable it then the error I originally reported goes away. I'd call that user error!

    Thanks for your help.
     
    A2GStudios likes this.
  36. russnash37

    russnash37

    Joined:
    Feb 22, 2017
    Posts:
    31
    Could you please share a list of requirements for the swim ability to function? From looking at your code and the demo scenes it seems to me that all that is needed is for the water to be set to use the 'Water' layer and for it to have a collider with IsTrigger set to true.

    I have performed the above on one of our game scenes, yet the player just walks underwater along the riverbed and doesn't even attempt to swim. We are using both AQUAS water and River Auto Material assets for our water.

    If I place our character into your demo Adventure scene, he swims correctly across the small pond in the scene.

    Thanks in advance for any help.

    Russ.
     
  37. A2GStudios

    A2GStudios

    Joined:
    Nov 21, 2016
    Posts:
    52
    I needed to get some help with the character animations. I am working on the same project russnash37 is working on, and it seems that no matter what I do I cannot get the animations to work. I started again with the Melee video you have, I have the weapon in hand and he walk around fine with it, but no animations when I hot the fire button. I checked the input to assure that the fire 1 button was still attached to the mouse, I do have it clicked OFF for aiming and needing to aim.I would like to include that we are using Inventory Pro with the setup. I also made sure the the Attack was set right to what is in the animator. Any more information I can give you to help me out just let me know, thanks for your time and your help.

    Just a thought, maybe what ever is causing the animation not to work is also causing the swimming not to work. The player moves , runs, and jumps just fine though.
     
  38. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Here are a couple of posts which should help:

    http://legacy.opsive.com/forum/index.php/topic,4815.msg24996.html#msg24996
    http://legacy.opsive.com/forum/index.php/topic,4564.msg23890.html#msg23890
     
  39. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Do you have a controller connected? Generally with input issues it's related to Unity's input manager not being mapped to the correct buttons with a controller connected. Other than that, do the demo scenes work? If they work then it is likely something else since input is at the project level.
     
  40. russnash37

    russnash37

    Joined:
    Feb 22, 2017
    Posts:
    31
  41. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    If the character is walking on water it likely means that the water collider's layer isn't set to Water. By default the character will ignore any collisions with the Water layer.
     
  42. russnash37

    russnash37

    Joined:
    Feb 22, 2017
    Posts:
    31
    I've just double checked the layers and both items in the hierarchy are set to the Water layer. My setup is as follows:

    Water with non-trigger collider
    - Sub game object with trigger collider and water script

    Further Information:

    I made a duplicate of our scene this morning and removed our character, then placed Dom into the scene and set him up. Dom successfully swam in our water setup so I am now sure that the issue is not with the water setup but with our character. Something must be amiss with the setup there.
     
    Last edited: Aug 22, 2018
  43. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Have you tried to compare the water ability settings between your character and Dom? Though it seems like it's a layer issue if your character isn't falling through the collider.

    Edit: one other idea is to check the priority of the swim ability. The abilities execute from top to bottom in the list so the swim ability should be near the top.
     
    Last edited: Aug 23, 2018
  44. russnash37

    russnash37

    Joined:
    Feb 22, 2017
    Posts:
    31
    I've checked the settings for Dom against our character and they are identical, I also have swim as the top ability. Unfortunately, 'Swim' becomes active yet our character still just walks across the top of the water.
     
  45. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Hmm.. unfortunately I'm out of ideas. If you send me a repro project I should be able to take a closer look at the cause.
     
  46. Simon-O

    Simon-O

    Joined:
    Jan 22, 2014
    Posts:
    51
    The Start Window doesn't seem to work properly for me... Buttons - which I assume should open the browser - do nothing.

    Specifically, I can't open the documentation or download the C# source code.

    DEfault browser is set fine and works for other apps.

    Any suggestions?

    Also... Is there a camera/input preset that maps directions (horz/vert) to screen orientation (EW/NS)? I'm looking for a top-down scroller-style effect (and later, I'll allow the player to rotate the camera in 90 degree increments).

    Thanks
     
  47. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Those buttons use Application.OpenURL which should be universal. You can get to those pages from here though:

    https://legacy.opsive.com/assets/ThirdPersonController/documentation.php
    https://legacy.opsive.com/assets/ThirdPersonController/documentation.php?id=50

    Right now the top down movement assumes that up is in the Vector3.forward direction. In version 2 it can be any orientation but right now it is restricted to that within the Camera Controller component.
     
  48. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
    I want to disable run (change speed) when the character is firing his weapon. I tried using aiming and forceaim but doesn't seem to be true when my weapon isn't forced aim.
    I tried adding it here in the shootableWeapon:
    Code (CSharp):
    1. if (m_CurrentStamina == 0 || m_Controller.forcedAim) {
    2.                     StopAbility();
    3.                     return true;
    4.                 }
    but m_forceAim doesn't seem to be true when firing. Any other way to disable change speed?
     
  49. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Instead of checking ForceAim try checking the Aiming property.
     
  50. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
    I can't find any variable that signifies the weapon is fired.
    if (m_Controller.Aiming || m_Controller.isAiming || m_Controller.forcedAim)
    {
    StopAbility();
    return true;
    }
    doesn't seem to work either. (and sorry i meant in the Change Speed script not shootableWeapon) There isn't any variable such as isFiring? maybe in the weapon scripts?
     
Thread Status:
Not open for further replies.