Search Unity

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,128
  2. Silvermurk

    Silvermurk

    Joined:
    Apr 29, 2016
    Posts:
    164
  3. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    I've gotten a couple of messages asking for a Deathmatch AI Kit update so I thought that I would post it here. Version 1.3.2 of the Third Person Controller delayed us a bit but we're now working on it again in conjunction with the next third person update. If you're unfamiliar with the Deathmatch AI Kit take a look at this and this post.

    Since the last post I have really started to work on the team behavior tree. Each team previously could only have one agent leading the formation but any number of agents can now lead the formation. This allows for a really dynamic gameplay because with a 4 person team you could have the following configuration:

    1 leader, 3 followers
    2 leaders, 2 followers
    3 leaders, 1 follower
    4 leaders

    The leader agent will do the searching for the enemy while the follower will follow the leader in a formation. Here's what that part of the tree looks like (it is the lowest priority branch):

    Search.PNG

    In addition to expanding on the formations behavior I have also added in a backup request system. If an agent sees an enemy they can request backup to get help from their teammates. If the teammate isn't doing anything important (such as engaging in their own combat) then they can decide if they want to go help. If the agent either kills the enemy or dies before the other agent gets to backup location then the backup request will be cancelled and the agent will go back to doing what they were doing before. Here's what that part of the tree looks like:

    Backup.PNG

    Sarah has finished with the first pass of the scene and is working on the new character. Overall things are progressing nicely and I should be able to post a WIP thread soon (I know that I've said that before.. I mean it this time :) )
     
    Silvermurk likes this.
  4. Silvermurk

    Silvermurk

    Joined:
    Apr 29, 2016
    Posts:
    164
    Unity fixed root motion problem with generics, but now i need a way to somehow attach TPC to an empty gameobject, if it`s even possable?:)
    Bad news - not i need to remake whole character model from scratch due to conflicting animations (
     
    Last edited: Jul 1, 2016
  5. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    I've replied to your thread on the Opsive forum - lets move discussion over there to reduce the noise in this thread :)
     
  6. eewoks

    eewoks

    Joined:
    Mar 21, 2015
    Posts:
    7
    Thanks that fixed it. I really appreciate youre support.
    One more small thing. Is there an easy check if an AI Agent is alive? i so far tried GetComponent<CharacterHealth>() to get the current health. Need it for my custom top-down targeting ability.

    Edit: I guess it would be better to send an event on dead (performance wise)?
     
    Last edited: Jul 1, 2016
  7. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    It's quite a pain using TPC's camera in VR, generally it means digging through code to have the camera, the position of which is locked in vr, be child of another gameobject and all references to move affecting that parent gameobject.

    Am I going about this the wrong way? It would be nice to have VR without any headaches
     
  8. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    You could check the Health.CurrentHealth every tick but the better alternative would be to subscribe to the OnDeath event:

    Code (csharp):
    1.  
    2. EventHandler.RegisterEvent(m_GameObject, "OnDeath", OnDeath);
    3.  
     
  9. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    I have a DK2 but I haven't tried it with the Third Person Controller recently. When I last tried it everything worked pretty painlessly. I do have planns to add VR integration out of the box but I haven't been able to get it to it yet.
     
  10. anomas

    anomas

    Joined:
    Jul 3, 2016
    Posts:
    47
    Hi opsive, ive bought your asset as a tool of learning and i must say your work is impressive.
    Going straight to my question: how would i be able to create transitions from walk to idle, run to idle, vice versa etc, using animations? Here is a video for reference, thats what i am trying to achieve.
     
  11. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    Glad you're enjoying it! By default the Third Person Controller uses a blend tree to switch between idle, walk, and run. If you don't want to use a blend tree you could create a new ability which changes states based on the input vector. You would use explicit transitions which would allow you to have specific transitions between the various movements.
     
  12. karmik

    karmik

    Joined:
    Oct 8, 2014
    Posts:
    124
    Hi Can i create a basic RPG scene with just 3rd person controller. I am planing to try out my concept first before i start serious work and I am anyway planing to buy this asset. So just checking if i can create a basic sceen with some basic enemy AI. notthing fancy
     
  13. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    Sounds great. RPG characters are no problem - there is a RPG movement type for the standard RPG controls. The Third Person Controller doesn't include any AI but it is ready for it. Both Behavior Designer and ICE Creature Control are AI solutions which work out of the box with the Third Person Controller.
     
  14. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    Hello,
    I pretty simple question but one I didn't find anything about in the docs: if I want to have a different set of controls than what's provided by the "Combat" etc movement types, do I have to override it all with abilities? In particular, I'd like to have a four-legged main character (without a rider), but I want some more "normal" controls for that. Almost like the Combat controls, but with the left and right keys rotating instead of strafing, and possibly other minor tweaks, especially to the camera.
     
  15. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    That almost sounds like the Adventure type - really the only difference between Adventure and Combat is when the character rotates. If the Adventure type doesn't completely cover your use case then yes, I'd recommend using the ability system. For this case it should be a pretty small ability which only overrides one or two methods.

    The CameraController does not have the ability system but as of the most recent update it does have states which may help. If you want to change more of the camera logic rather than the settings though you'll need to get into the CameraController code. If there's a particular method that isn't marked as virtual but you'd like it to be let me know and I'll make that change so you won't have to with every third person update.
     
  16. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    It's true that the adventure movement might be what we need, but we don't want the free camera movement associated with it. So I'll try either adjusting the camera settings or creating a new ability.

    Also, is it even safe to use adventure or combat movement for four-legged characters? Don't we lose whatever you do with those foot colliders?
     
  17. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    I've mentioned our next asset, the Deathmatch AI Kit, a few times and we're far enough along now that it has it's own WIP thread. This post has all of the details.

     
    Deckard_89, TheLetterS and Arganth like this.
  18. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I may be missing this, but is there some setting that allows the character to slide more freely when colliding with obstacles? Right now you only get sliding in very restricted conditions. Most of the time, you just seem to get stuck or even stutter a little as it tries to move forward.

    EDIT: I think I found it. Is it supposed to be Stop Movement Threshold? If so, I set all the way to 1 and although it does improve it a bit, it's still a bit sticky in most situations. Any ways to improve it more?
     
    Last edited: Jul 21, 2016
    Arganth likes this.
  19. Arganth

    Arganth

    Joined:
    Jul 31, 2015
    Posts:
    277
    yeah would love a way to have less of this "stickiness"
    one reason I am looking at puppetmaster
     
    magique likes this.
  20. uni7y

    uni7y

    Joined:
    Jul 23, 2012
    Posts:
    287
    Question... will you ad the Quest System Pro also to the Integrations list? That would be great!
     
  21. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    The Stop Movement Threshold does sound like it contributes to it. This value ranges from -1 to 1 will stop the character from moving if you hit an object head-on (a value of 1) or on the side (a value of 0, it uses a dot product). Beyond that it's Unity's physics system doing the stopping - you could try to set a different physics material on the character to reduce the friction.
     
  22. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    Sure, I'll get in contact with @jorisshh
     
    magique likes this.
  23. uni7y

    uni7y

    Joined:
    Jul 23, 2012
    Posts:
    287
  24. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    For the first part do you mean the Movement Pack (you have Tactical Pack list twice)? To answer your question, the Third Person Controller can work with both the Tactical and Formations Pack and there is no overlap. The Tactical Pack creates groups which can be used to attack a target. The Formations Pack does not have any attacking and is more focused on moving from point A to B in a formation. The Deathmatch AI Kit will not require the Tactical or Formations Pack but it does a use similar technique for behavior tree communication as the Tactical and Formation Packs.

    (I've talked to Joris on Quest System Pro integration - I haven't played with Quest System yet but do you have any suggestions for what you'd like to see integrated between Third Person Controller and Quest System Pro? Joris is working on the Behavior Designer integration and said that it should be pretty easy)
     
  25. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    By changing the grounded movement physics material to frictionless it helped some more. I think it's acceptable at this time. I may also look at Puppet Master to do more to give another avenue of improvement.

    EDIT: Ugh! I was wrong. Going frictionless causes sliding down hills so not a good solution. I will continue to try things.
     
  26. uni7y

    uni7y

    Joined:
    Jul 23, 2012
    Posts:
    287
    Ok, Thanks for the fast reply! it is all clear now. Yes I did mean the movement pack, I see I get that one for free if I'm the owner of the Behavior Designer pack :)
    I don't know yet because I have not yet bought the Quest System Pro, it is in my cart also with Inventory Pro... So I have to find out and have a lot to learn the coming weeks :)

    Just bought it so the fun can start
     
    opsive likes this.
  27. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    You can set another friction material for when your character is on a slope. This friction material is triggered with a forward raycast though so it won't switch to it if your facing on a downward slope. I'll make an adjustment so this same material will be switched to on a downward slope which should give you some more control.
     
    magique likes this.
  28. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    Is there some way to safely remove scripts from our character that we're not using? I'd like to remove at least the inventory functionality, but if I do, animation states won't properly update any more (because DetermineState exits early if inventory hasn't been initilized).

    If we can't remove those, can we at least stop them from logging errors about how they need all those inputs to be generated? We want to use our own set of inputs.
     
  29. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    The Inventory is not required, but you'll need to execute the following event so the AnimatorMonitor works:

    Code (csharp):
    1.  
    2. EventHandler.ExecuteEvent(m_GameObject, "OnInventoryInitialized");
    3.  
    Really only the following Third Person Controller components are required for basic character movement:

    RigidbodyCharacterController
    ControllerHandler
    AnimatorMonitor
     
  30. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    OK, thanks!

    And I can remove the rest without needing to fire any extra events?
     
  31. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    That's correct!
     
  32. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Hi Justin. Just checked out your Shooter Demo (I presume this is the latest build?) - noticed that using the shield and picked up a weapon (both used as a combo) - pistol doesn't aim correctly. I also picked up another pistol and it shows both through the shield - maybe we could have a constraint in there not to allow more than two items to be used at once?
     
  33. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    I added that message call to another script at Start, and the OnInventoryInitialized method gets called as expected. However, m_ItemName still remains null, which quits DetermineState early.

    Edit: And if I comment out the line that checks for m_ItemName, I get null references when it tries to check my primary item... So it seems the AnimatorMoninor definitely expects inventory to be there and functioning..

    Edit 2: I think the InitializeSharedFields methods fails to initialize m_ItemName because it can't find the inventory script where the "ItemName" method has been defined...

    Edit 3: Oh well, I can probably live with the Inventory script. It's the InventoryHandler script that asks for all those input settings.
     
    Last edited: Jul 21, 2016
  34. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    Are you referring to the web demo? I just tried it and wasn't able to reproduce either of those issues - there should only be one item in the hand at a time.
     
  35. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    It has been awhile since I tested just the core set of components are you're correct. It's a pretty quick change though to prevent the AnimatorMonitor from needing the inventory. Go to DetermineStates and remove:

    Code (csharp):
    1.  
    2.   // Do not determine any states if the inventory hasn't been initialized yet.
    3.   if (m_ItemName == null) {
    4.     return;
    5.   }
    6.  
    And add the following to HasItemState:

    Code (csharp):
    1.  
    2.   stateChange = false;
    3.   if (m_ItemName == null) { // <-- NEW
    4.     return null; // <-- NEW
    5.   } // <-- NEW
    6.  
    And once more in ItemUsesAbilityLayer:

    Code (csharp):
    1.  
    2.   if (m_ItemName == null) {
    3.   return false;
    4.   }
    5.  
     
  36. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    Its on this one... http://www.opsive.com/assets/ThirdPersonController/shooterdemo.php

    First I pick up the Pistol, then the Shield. Aim and move the mouse the weapon remains pointing downwards. Then pick up the second pistol and you will notice two pistols are aiming through the shield.

    tpsddw.jpg
     
  37. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    Ah, thanks for the steps. I was picking up both pistols first. I just tried in my local copy and wasn't able to reproduce it with the same steps. It'll be fixed in the next version :) If you need a fix beforehand I can send you a new set of files as soon as I have a more stable version (I'm still working on IK and item initialization in my dev branch)
     
  38. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    No hurry, happy to wait :)
     
  39. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    Thanks for the response on the Inventory! Though I think I'll prefer to just keep the inventory, as I want to avoid editing your files if at all possible.

    Another question, though: Is any of the Ability virtual functions called in Update, instead of FixedUpdate? I'd like to put some Input.GetButtonDown code somewhere, but in FixedUpdate that stuff doesn't reliably fire once and only once.
     
  40. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    These changes will be in the next version :)

    To keep things clean I try to decrease the amount of input checking done within abilities. In your case if you want to receive callbacks when the button is down your ability can register for an event with the controller handler:

    Code (csharp):
    1.  
    2. ControllerHandler.RegisterAbilityInput(string buttonName, string eventName);
    3.  
    You'll also need to register for the event within your ability. This then allows the controller handler to detect your abilities input and it works across the network. RegisterAbilityInput is private in the current version but you should switch it to public (I've already made that change).
     
  41. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    Thanks!

    And sorry, yet another question / bug report: I seem to often have a problem where a particular Ability I've written fails to appear in the "add ability" popup on RigidbodyCharacterController. I debugged it in the code a little and found that it's excluded because there's already that component (my Ability script) on the game object. But I can't see it, not in Normal nor in Debug mode... "Find References in Scene" does list my game object as having this component..

    Yesterday I once actually saw that script and removed it (I forget if that helped). But now I don't see it and I definitely never added it... The script is called "Movement" and is in a custom namespace "MyGameAbilities". For a moment I thought it was tripping on the "Movement" behaviour designer Action somehow but I confirmed it's indeed finding "MyGameAbilities.Movement".

    Does your system add these to the game object and does it somehow then hide them?

    Edit: I removed literally every component and every child game object from my character (leaving an empty game object) and "Find References in Scene" still lists it as referencing "MyGameAbilities.Movement"...

    Edit 2: It might be relevant that this is happening with a character that I duplicated from another character that had this ability. But I then removed everything and re-created it from scratch with Character Builder...
     
    Last edited: Jul 22, 2016
  42. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    Abilities are regular MonoBehaviours so the RigidbodyCharacterController inspector hides them with HideFlags so they can appear in the ability list. It sounds like the inspector isn't synchronized - do you have a way to reliably reproduce it so I can take a closer look?
     
  43. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    Well, the reproduction should be as simple as:

    1) Add an Ability to a character

    2) Remove all Third Person Controller components from the character (RigidbodyCharacterController is probably enough but this makes it more obvious)

    3) Right-click on the script of the Ability you added earlier and you should see your character listed. So clearly removing RigidbodyCharacterController leaves a hidden ghost hanging around on the game object...

    4) If that seems too innocent to worry about, try setting up Third Person Controller again and you'll find that the Ability is not listed under RigidbodyCharacterController, even though the component is (hidden) on the game object. But it does block you from adding it via the popup...

    Edit: As an aside, is there a "correct" way to remove all the Third Person Controller components? I often want to start over with a character but running the Character Builder again will duplicate stuff (or throw errors if it can't add everything again, such as foot rigidbodies), so I need to start clean every time.
     
  44. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    That would do it.

    Open RigidbodyCharacterControllerInspector.cs and add a private m_GameObject field then assign it within OnEnable:

    Code (csharp):
    1.  
    2.   // Store the GameObject reference in case the RigidbodyCharacterController is destroyed.
    3.   m_GameObject = (target as RigidbodyCharacterController).gameObject;
    4.  
    Now add the OnDestroy method:

    Code (csharp):
    1.  
    2.   public void OnDestroy()
    3.   {
    4.   if (target == null) {
    5.   // All of the abilities should be removed along with the RigidbodyCharacterController.
    6.   var abilities = m_GameObject.GetComponents<Ability>();
    7.   for (int i = abilities.Length - 1; i >= 0; --i) {
    8.   DestroyImmediate(abilities[i], true);
    9.   }
    10.   }
    11.   }
    12.  
    This will remove all of the abilities when the controller is destroyed.

    Right now you'll have to manually remove all of the components. The Character Builder requires a fresh character. I have it pretty high on my list to create an editor which will allow you to more easily manipulate existing characters but I haven't been able to add that yet.
     
  45. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    I did that and now it deletes the Ability from the list when I enter play mode.
     
  46. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    Change the first OnDestroy if statement to:

    Code (csharp):
    1.  
    2.   if (!EditorApplication.isPlayingOrWillChangePlaymode && target == null) {
    3.  
    I just tried it and the abilities were still there.
     
  47. lofwyre

    lofwyre

    Joined:
    Apr 19, 2007
    Posts:
    174
    I am building a game where the player can change to a car and drive around. My thoughts so far is to have the car using a different camera and controller and simply hide the third person controller character, disable the scripts and enable/show the car. Do you think this is the easiest way? How would I go about hiding the character?

    Thanks
     
  48. lofwyre

    lofwyre

    Joined:
    Apr 19, 2007
    Posts:
    174
    To be a bit clearer, for the car I was thinking of using the "fun car kit" asset from the asset store. It has the right level of cartoony arcade driving. I need a way to move from one controller to the other while hiding and showing the associated camera and player gameobject.
     
  49. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,128
    That is almost the same method that I used with the Edy's Vehicle Physics integration (the only difference is that the car is always visible). Even if you don't have Edy's Vehicle Physics you should take a look at the integration scripts - there is a DriveEdyVehicle ability and the method SwitchControllers does the switch.
     
  50. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Back with this and puppetmaster. I spent some hours today trying to figure out the strange behavior when jumping with the puppetmaster integration where the character would hover at the start of the jump then pop up after a delay.

    Only happens when puppetmaster is enabled. Is there anything I'm doing wrong? (I imagine there probably is)
     
Thread Status:
Not open for further replies.