Search Unity

Character Controller Pro

Discussion in 'Assets and Asset Store' started by lightbug14, Jan 15, 2020.

  1. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    I'll change the jump/gravity calculation just a little bit:
    jumpAutoCalculate.gif
     
  2. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    So this is what I've been working on:
     
    SilverStorm and lightbug14 like this.
  3. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72
    Looks really cool, nice work, how long have you been working on it? What platform is it coming to? is there a steam page?
     
    Last edited: Mar 17, 2021
  4. bunnybreaker

    bunnybreaker

    Joined:
    Dec 10, 2013
    Posts:
    23
    OMG, Thanks a lot. This immediately helps me take out a li'l spaghetti code.
     
  5. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Congratulations, that looks really nice! ;)
     
  6. apprenticegc

    apprenticegc

    Joined:
    Apr 21, 2012
    Posts:
    25
    Hello, when I try to set player(with CharacterActor component) position directly(for the sake of changing level). I see the player position reset back. I then manually disable CharacterActor, PhysicsActorSync and PhsicsComponent3D components in the editor and enable these components, it works as expected. However when I try to disable, enable these components via code(waiting several seconds). The position of player changes but drag back still after enabling these components.

    I don't know how to do this changing position after new level loading task. Do I miss any part of documentation? Please help.
     
  7. EntangledGames

    EntangledGames

    Joined:
    Mar 8, 2013
    Posts:
    9
    Im getting this weird bug with the newest version.

    It happends whenever I set UseRootMotion = true and my framerate is higher then 60fps (My project usually runs at 300fps in editor according to the stats tab). It makes any ccp controller playing a rootmotion animation lift into the air. it doesn't happen if I run the same animation with UseRootMotion = false or If I limit the framerate to 60.

    The exact same project works fine with ver 1.3.0, this only happends with ver 1.3.1 onwards.

    Any idea why this is happening?

     
    Last edited: Mar 28, 2021
  8. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72

    This might be related to what I'm seeing as well, when I toggle the Use Root Motion, my character goes back to 0,0,0, I would assume my FPS is above 60. I believe it only happened since 1.3.2. I put a video in the discord.

    @lightbug14
     
    Last edited: Mar 29, 2021
  9. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Sorry for the delay, internet issues :( I'm working on that right now!
     
    EntangledGames and Broudy001 like this.
  10. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Ohhh i know why this is happening, it seems to be an update mode conflict. Are you using "Normal" UpdateMode (Animator)? Try to change this to "Animate Physics" (after FixedUpdate) and see what happens.

    Let me ask you something, Do you really need to use a "normal" update mode in your project? because the character was built on top of FixedUpdate (animation too). If the answer is no, then i guess you should change the update mode (CCP should also force this update mode if root motion is enabled, unless there is a very good reason not to).
     
    Last edited: Apr 4, 2021
  11. EntangledGames

    EntangledGames

    Joined:
    Mar 8, 2013
    Posts:
    9
    Indeed my animator controllers are set to normal, that is because when you set it to "Animate Physics" the rootmotion movement of an animation can push other controllers / rigidbodies even if "Can Push Dynamic Rigidbodies" is set to false in the CharacterActor component.

    This is a problem as my combat system relies on each hit applying a consistent pushback on enemies, otherwise the flow of the combos can be broken by unexpected/random pushes applied by the animations using rootmotion.

    Is there a way for rootmotion movement and an animator with Animate Physics to not push rigidbodies? "Can Push Dynamic Rigidbodies" is being ignored in that case.
     
    Last edited: Apr 4, 2021
  12. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72
    I'm using animate physics and it resets the location back to 0.0.0 when I tick/untick the use root motion
     
  13. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Have you tried to ignore those rigidbodies by using the layer mask (below "can push dynamic rigidbodies")? You can change this mask at runtime if you want.
    The actor predicts (based on the current velocity) if there is some obstacle in its way (static, kinematic, dynamic, etc). This applied to scripted movement and root motion movement.

    In any case I'll try to introduce this "normal" update mode if possible.

    I've fixed a similar bug, although for me that happened when enabling the actor (the "use root motion" property worked fine). I tried to reproduce this by disabling/enabling "use root motion" in 1.3.2... no success :(. I saw the video (discord), Have you tried to replicate this behaviour without MxM involved (using regular root motion clips)?


    This was causing the problem (PhysicsActor-> OnEnable):
    Code (CSharp):
    1. protected virtual void OnEnable()
    2.     {
    3.         if( postSimulationUpdateCoroutine == null )
    4.             postSimulationUpdateCoroutine = StartCoroutine( PostSimulationUpdate() );  
    5.  
    6.  
    7.         if( animatorLink != null )
    8.         {
    9.             animatorLink.OnAnimatorMoveEvent += OnAnimatorMoveLinkMethod;
    10.             animatorLink.OnAnimatorIKEvent += OnAnimatorIKLinkMethod;
    11.         }
    12.  
    13.    
    14.         ResetInterpolationPosition();  //<----
    15.         ResetInterpolationRotation();  //<----
    16.    
    17.     }
    Enabling the actor (PhysicsActor) wasn't resetting the target position/rotation (interpolation), this is why the character went back to the last position.

    There was a problem with PhysicsActorSync as well:
    Code (CSharp):
    1. void FixedUpdate()
    2.     {
    3.         if( !physicsActor.enabled )   //<---- This
    4.             return;  
    5.    
    6.         physicsActor.SyncBody();
    7.     }
     
    Last edited: Apr 4, 2021
  14. bluevariant_dev

    bluevariant_dev

    Joined:
    Feb 5, 2020
    Posts:
    3
    @lightbug14 How to implement one way platform like k2d. Thanks
     
  15. EntangledGames

    EntangledGames

    Joined:
    Mar 8, 2013
    Posts:
    9
    Just tried it using version 1.3.0 and my actor was still pushing other rigidbodies even when Can Push Dynamic Rigidbodies is set to false and the mask is set to nothing. seems like in that version rootmotion always pushes obstacles.

    I updated to 1.3.2 and in this version it seems to be working fine, rootmotion and "Can Push Dynamic Rigidbodies" = false does not push rigidbodies, and setting the animator to "Animate Physics" got rid of the weird upwards push that I first reported.

    For now ver 1.3.2 seems to be working fine for me, Thanks for the help.
     
  16. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72
    @lightbug I haven't tried with just root motion, I'll try to get it to happen without mxm. In the place where it's happening I'm fading out of mxm into normal mecanim for the falling which then blends back into mxm for the movement after landing, might have something in there, but it didn't happen prior to 1.3.2 as I had the falling etc working fine.
     
  17. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    I haven't yet purchased CCP, but I'm really impressed with the demos and I have been reading through the documentation for a while to understand the input system, character brain, and other methods. I have a question about the New Input System.

    Is New Input System supported by default? Do you have demos with New Input System support?

    What is necessary to get Gamepad support working? I notice the demo has no gamepad support, and the docs have no mention of Gamepad at all. Is this intentional? It seems like an odd omission.

    I'm quite fond of the New Input System, and I'm reluctant to leave it behind, so I'm curious how much work is necessary to get up and running. I found a reference to the New Input Handler in the docs, but it gives the impression that there are problems with it.

    I'm fully prepared to do the legwork to make CCP work with my game but I'm wary of having to spend a long time before I can move a character or a capsule with a gamepad.
     
    Last edited: Apr 5, 2021
  18. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72
    I've always used the New Input System with CCP. Only a couple of things to do to get it working, and I believe its going to become the default in CCP at some stage in the future.

    I've not had any issue getting it working, and @lightbug has always been very responsive to any help needed.
     
  19. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    @Broudy001 Thanks! That gives me confidence that it's worth the gamble.

    Okay, I've just bought the system. Looking forward to getting started with it! :)
     
    Broudy001 likes this.
  20. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Nice to hear that! One of the big changes i made to root motion was based around that. In the previous versions (<= 1.3.1) root motion was treated as a separate thing (scripted logic -> handled by CCP , root motion logic -> handled by Unity). Now root motion and scripted movement both go through CCP, this is why it works now :).

    Adding this + new interpolation was (is) tricky as hell, fix version 1.3.3 is coming tomorrow (maybe).

    Interesting, there must be something there. In this case "use root motion" is only preventing (or allowing) FixedUpdate (OnAnimatorMove).
    How are you fading mxm into mecanim?


    Supported? Yes
    Included? Yes (look at the InputSystemHandler.cs file)
    Enabled by default? No (uncomment the entire file).

    The new input system will be the default system (>= 2.0.0). I wasn't sure about including it with the Core package (2.0.0 will be separated into "Core package" vs "Demo projects"):
    1. Core
    2. Demo project A (Requires new input system)
    3. Demo project B ? (Requires new input system)
    4. etc... (Requires new input system)

    I'll probably include it anyway (for the "core"), everyone should switch to new input system.

    Important: The "character controller" (CharacterActor) and the input system implementation are two different things. You are free to use whatever input system you want (for the player at least ... with your own gameplay logic). In this case, Unity's input system needs to be implemented (via an "input handler") only if you want to use the action system included with CCP (NPC/Player input signals).

    You are right, i should have included Gamepad support for the Input Manager (old). In any case, this should work in the same way the "Mobile" scene works (UI Joystick).
     
  21. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Sorry, i missed that.
    K2D handles dynamic OWP really well. On the other hand, CCP handles static OWP + slow OWP (at the moment, not exactly fast moving platforms). I'm working on fast moving OWP, i'll try to introduce them soon (1.3.X cycle if possible). i'm not sure about that "like k2D" you mentioned.
    In any case, one way platforms can be set up by assigning one particular layer to the platform (you can use multiple layers for multiple platforms if you want). After doing that just go to the CharacterActor component and put those layers (OWP) into the "one way platforms layer mask" field.
     
  22. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72
    I'm not sure the specifics on how it works, but MxM includes a function to blend to mecanim and then back out.

    I did more testing today, and couldn't get the use root motion thing to fail. I'm on a different machine though that should have any effect other than this is a laptop which might struggle with the fps, but should be above 60.

    Also I was able to get my rotation working without the jerkiness, so happy days :) as always thanks for your help.
     
    lightbug14 likes this.
  23. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72
    Installed 1.3.3 today and so far no issues :)
     
    lightbug14 likes this.
  24. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    I was able to implement New Input System support for the demos, but I'm struggling to get started building my own characters not using the demo assets.

    Question for people who have implemented CCP. How did you get started? I'm finding it rather impenetrable right now. I am prepared to do plenty of work, but I can't figure out whether I am expected to code everything from scratch or pick through the demo assets to try to figure out how they work. The NormalMovement code is 750 lines and refers to a bunch of extra classes... should I be copying this?

    I want to use CCP, and I'm desperately trying to figure out how to get started. Are most users throwing out the demo controls and treating it like a regular Unity Character Controller?

    Code (csharp):
    1. DirectoryNotFoundException: Could not find a part of the path "C:\Users\Docky\Documents\GitHub\_docky_\2021_obby\Docky_Obby_Unity\Assets\Character Controller Pro\Implementation\Resources\template-character-state.txt".
    2. System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO
    3.  
    I also ran into errors when trying to create my own State. I ended up using the YourState example to create my own states, but I would prefer to use some of the demo states as a foundation.

    @lightbug14 I'm curious about the mentions of v2.0.0. Are you about to replace or release a separate edition of CCP?
     
  25. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72

    I use all my own states for everything. I might depending on what I'm doing pull bits out of the demo states. I use the right click menu option to create a new state, then do everything myself.

    My current layout is

    BaseState
    Locomotion state - > general, falling, sliding states
    Combat state -> multiple combat states

    I use this as there are parts of what I'm doing I want in all states but then only some in others. I'm also using motion matching so there is some common elements I want in my states for that, and I'm mostly using root motion but some states like falling and sliding I'm not so I change the use root motion on entry to the state.
     
  26. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    You are free to do whatever you want. NormalMovement is there for you (as an example), if you want to use it in any way you could:
    1. Put it outside the CCP folder and do whatever you want with it.
    2. Create your state and copy+paste the logic.
    3. Derive from it (use it as your base class) by creating a new state. Again, always put your content outside CCP folder).
    At the end it depends on what you are trying to achieve. Can you give an example?

    Those "extras" can be found under NormalMovementExtras.cs. Don't worry too much about those classes, they are just plain c# class (serialized) that contain public variables (mostly). I used them in order to extract/separate all those specific variables and functionalities out of NormalMovement.


    I'm not getting errors, Are you creating the state using the project window (right click, CCP/...)?
     
    Last edited: Apr 14, 2021
  27. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    --> Replace.
    This one will most certainly break compatibility (this is why is a major release). By "break" i don't mean you are going to get a completely different asset. However, some things will be heavily modified (e.g. action system, ability + state system, etc).


    ...No ETA yet.
     
  28. Blomidev

    Blomidev

    Joined:
    Dec 16, 2015
    Posts:
    11
    Hi!

    The asset is working wonderfully, but I am having a lot of trouble placing a fake shadow under my character. I am using a mesh decal for this purpose, and it jitters up and down consistently whenever the character is not grounded.



    I have successfully used mesh decals for this purpose with other character controllers, and have tried two different mesh decal libraries so far. Both have this problem, but only when used by Character Controller pro.

    At first I thought it might be an Update vs FixedUpdate problem, but changing the decal implementation to recalculate on FixedUpdate didn't solve the issue.

    This is the only problem I'm having with an otherwise great asset. Let me know if you have any ideas on how to fix this.

    Thanks,
     
  29. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi @ThomAThomson ,

    Where can i find them? (i'm assuming you are not talking about decal projectors from HDRP)
    Where is this "mesh decal" located (character hierarchy)?


    Also, What version of CCP are you using?

    A) If you are using 1.3.X then your character will get interpolated (CCP's custom interpolation). This means that you can put your fake shadow wherever you want inside the character hierarchy (under the root = character).
    If your "decal projector" follows any Transform component associated with the character (the root, graphics root, and so on), then everything should be working as expected (it is just another child getting interpolated using Update).

    B) If you are using either 1.1.X or 1.2.X then you probably need to add the decal under "Graphics" (by default this is the "graphics root"). The character (collider + rigidbody) updates itself using FixedUpdate. The visual part of your character (a child) will follow the root (interpolated movement, no problems). However, something this graphics object might be getting updated using Update (especially if you are using CCP's graphics root controller component). If you are going to add this fake shadow to the character please use the "graphics" object, not the "character" (this is useful for 1.3.X as well).

    I guess you could also try to disable the GraphicsRootController component, just in case this is causing trouble.
     
  30. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Also @dock just use the prefabs 3d with camera it's ready to go.
    That's what I'm using.
    @lightbug14 Got your asset integrated nicely but when I click play the camera snaps above the character and looks down at him from above and I have to correct with my mouse to roll it back down behind the character. What's causing this and how to fix it so it starts behind my character?

    Also my character is walking up many steps that seem a bit too high to walk up so I tried to lower the step up variable in the character actor script but te inspector has locked it so it wont go below 0.6 however the script itself shows 0f as the minimum so I'm confused.

    And lastly you have already implemented some basic AI behaviour like follow and roam so I was thinking do you think I would have to purchase a behaviour tree plugin to get things like seek, attack, flee to make an action RPG where I cycle thought the right states to fight enemies or do you have a setup for this already? If not what tool would you recommend?

    *Update looking at the older version of the package I can see that the function was working just fine so thi
     
    Last edited: Apr 25, 2021
  31. Blomidev

    Blomidev

    Joined:
    Dec 16, 2015
    Posts:
    11
    Hi @lightbug14, thanks for getting back to me so quickly!

    I was able to work around this. It turns out I needed to recalculate the decal in LateUpdate, so that the mesh positions are set after CCP's interpolation.

    Just for further information:

    I am using Character Controller Pro 1.3.3, and the Mesh Decal solutions I've tried are Easy Decal and Simple Decal System. I have my fake shadow under the graphics object, and have tried with the Root Controller enabled and disabled with the same effect.
     
  32. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    I haven't heard back from him in a few days would you say email gets a faster response?
     
  33. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Good to know that! That makes sense now, CCP PhysicsActor's interpolation runs in Update using the default ExecutionOrder (10). There is a chance those decal assets are using a default execution order of 0, this is probably causing some conflict between character and graphics. Any graphics related stuff (in this case Decals) should be executed after the game logic (in the same way Render related messages run after Update messages), so using either a higher execution order (Update) or LateUpdate should be the way to go. In this case using LateUpdate seems to be good enough.

    It is complicated to answer. The current system allows the user to modify the character actions struct via code (low level stuff, basically pressing buttons). The BT will allow you to trigger some functionality that you will need to implement on top of the actions (e.g. FollowBehaviour). If you implement this middle layer correctly (and the BT is able to call these low level AI instructions) then i guess everything should be fine. It also depends on the BT solution we are talking about.

    It should be something like this:

    Behaviour Tree (e.g. follow to Target)
    --> AI Behaviour (Follow to X)
    --------> Locomotion State (Locomotion logic)
    -----------------> Character controller (CharacterActor)

    I'm working on that, i think that would be pretty cool to implement. Just to be clear, if you really need cinematic stuff i would recommend Cinemachine. My Camera3D script is there for demo purposes (not really the focus of the asset).

    This is fine, since the character is a capsule it should be "impossible" (for 1.X.X at least, not for the next 2.X.X) not to walk over some low height steps. In this case, any "< radius (width/2)" step will be walkable. This is related to the grounding algorithm.
     
    Last edited: Apr 27, 2021
  34. Wilomomo

    Wilomomo

    Joined:
    Jul 6, 2017
    Posts:
    6
    Hi, I've bought your CCP asset, and first thing : Great job, it's awesome !!!
    But i've got an issues, I'm trying to make a first person controller that can walk on a spherical planet. My planet spin on it self and I want to make my character follo the rotation.
    I've try :
    -Add a kinematic rigidbody on the planet, an set "Support Dynamic Ground" on true, but there is some imprecision that make my character shake a llittle bit (very visible with a FP camera)
    -Set my character as a child of my planet, but it just ignoring and my character don't move with my planet

    Do you have an idea of how I can achieve that ? I've try to look at your script to know why the parenting is ignored but I don't understand all and I am a little bit lost ^^
     
  35. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, thanks, i'm glad you like it!

    Your planet should move/rotate using MovePosition/Rotation (kinematic body) + FixedUpdate. Remember that the planet is just another moving "platform". Parenting is not supported since it is normally a trick rather than a solution.

    If you want to move/rotate any kinematic body (related to this asset or not) you should always use MovePosition/MoveRotation, this will produce a smooth transition between posA/rotA and posB/rotB (interpolation). Since the character is being interpolated, the planet should be interpolated as well, otherwise you will get jittery results. Remember to enable interpolation, otherwise rb.MovePosition = rb.position.
    Also, the script execution order doesn't matter since movement will be executed during the simulation (after FixedUpdate).


    This is an example, movement + rotation:
     
  36. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    @lightbug14 Hi ah sorry I didn't quite understand your answer regarding why i can't change the step up variable to 0.3 because the value won't go below 0.6 when i try to reduce it in the character inspector. The character should walk over tiny obstacles but not anything higher than 10 cm so for that I think i need 03 in the step up variable but whats preventing me from changing it from 0.6 to 0.3?

    In regards to the camera snap issue I've made some progress by limiting the pitch or yaw variables so that it can't look so high or low compared to the default and that fixes that issue.
     
    Last edited: Apr 29, 2021
  37. C12D17

    C12D17

    Joined:
    Aug 21, 2013
    Posts:
    2
    Hi, I recently purchased the CCP and so far I'm really loving how it works.

    Right now, I would like some help getting states working. I watch Brackeys' Unity tutorials and learned from those how to create a state machine using the Animator. I want to create my own states and control it from the Animator using behaviors for each state. Would that be possible using CCP, or if not is there a way to control each state's behaviors in a single (or multiple) scripts?
     
  38. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    CCP is a character controller system and uses the state machine that comes with Unity.
    Inside the animater of the 3d character demo prefab click the default node that's orange and to the right of it in its settings you will see the "add behaviour" button which can launch scripts and stuff so this should be what you want if the normal animator transitions are not enough for you.

    Behavior designer (asset store) can do it too using behaviour trees and handles AI nicely and there is even this free tool: https://assetstore.unity.com/packages/3d/characters/animator-state-machine-utility-23450.

    I recommend you keep looking up tutorials in the animator because there are things like the parameters and double clicking the orange default node state in the demo animator which opens up the sub state machine showing jog, idle run and how they blend so there are multiple ways to do what you want.
     
    Last edited: Apr 29, 2021
  39. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    @lightbug14 I don't like what you've done with the animator it's a mess. You've added blend trees and put nearly 10 states into the Normal Behaviour script that uses a really annoying blend tree paramater. I think you have other scripts that call these states the problem is I have put my own idle animation in there and when the character stops running he snaps a bit too suddenly into my custom idle animation and it looks wrong. I tried to tweak the parameters in that blend tree but it always changes the idle into crouching or something it's a mess. You have not put the transitions of the animators into the base layer which is why I'm confused on how to edit this properly to make the animation from run or jog back into idle smooth and less instant so how do I go about doing this using your blend tree or should I be eiditing one of your scripts?

    I have also added my own run animation and the player holds the sword above his head when running like a mad man and it's ok but when running up stairs he jitters his animation so there's something going on like his arm goes up and down as if there's state conflicts hmmm.

    I thought this was all automated and then I found out you have many scripts controlling all these transitions which was a bit disappointed but on the plus side it means since you have prefabs ready without animations that I can use those capsules and implement my own animation logic without those god forsaken blend trees and parameters am I correct in saying I can simply use the movement physics and camera logic and write my own animations in with inputs without much hassle because the way you have set this up I would have no idea how to create an attack animation and set it up where or in what script?
     
    Last edited: Apr 29, 2021
  40. C12D17

    C12D17

    Joined:
    Aug 21, 2013
    Posts:
    2
    Oka
    Okay, after taking another look at the CCP, I think I'm starting to understand how everything works now. I'm gonna mess around some more with it this weekend and try to better understand how to use it.

    Thanks for the response.
     
  41. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Yes, in order to do that you would need to ignore the demo states (and state machine) that comes by default with the asset. These states are Monobehaviour scripts, this is why you need to ignore them (since you will be using a state machine behaviour). The rest is the same, you need to get a reference to the CharacterActor (the character controller) and do all the things you want with it.
    See this thread if you want to extend SMB:
    https://forum.unity.com/threads/extending-statemachinebehaviours.488314/

    The only thing i added to the blend tree was the "Crouch" part (2 clips + height parameter), that's it.
    Don't tell me this is an "annoying" blend tree:
    upload_2021-4-30_3-55-39.png


    That's a design question really (code + mecanim). You have one Animator component, that doesn't mean NormalMovement (for example) must be responsible for it all the time. You can separate movement (basic locomotion) and combat (100% animation) by using multiple scripts at the same time.

    In the past i integrated a combat asset (i don't remember the name) adding a combat script (responsible for inputs + animations) and modifying the NormalMovement animator controller (using an "override" layer on top). Combat usually requires instant feedback, so the best way to achieve this is by Playing/Crossfading to an attack state. This worked because the project was already using NormalMovement, so adding combat (three weapons i think) was really easy at this point.

    Regardless of how you approach this, there is something you need to consider very seriously: Demo states are there only for demo purposes. The example states are "ready to go", When i say "ready to go" i don't mean they have been designed to be 100% customizable (even though i tend to make them as much flexible as possible). By "ready to go" i really mean they work for the demo, and that's it.

    If the animation part is causing you some trouble then check:
    A) threshold values
    B) blend tree parameters (see the state code as well)
    C) The avatar settings.

    There are also tricks associated with mecanim. For example, see how i've duplicated the CrouchMoving clip in order to prevent the blend tree to mess things up:
    upload_2021-4-30_2-29-3.png
     
  42. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    So for the demo why did you choose to go the sub state machine with blend trees route when instead you could have stick with the base layer where you can control the animation transitions better and also activate behavior scripts to better keep your code in the loop? What was the reason as I'm trying to understand better because I consider the base layer with script control much better but I also have no experience with sub state and blend trees..

    Second you mentioned to edit the state code so what scripts are you talking about exactly because part of the confusion is there are so many scripts and I'm not sure how they are being bound to all together.

    Third I was asking saying it would be ok for me to use the prefabs that are capsules with cameras to start my state coding and I would be ok right-as in I could add my own animator states and there wouldn't be issues right?

    Lastly I asked earlier and didn't understand your answer I said my character is walking up stair slabs I consider a bit too tall and so I want him to not to do that so I've found the step variable and the inspector won't let me take it down to 0.3 it gets stuck at 0.6 how to fix because 0.6 causing problems?
     
    Last edited: Apr 30, 2021
  43. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Those are not sub-state machines, only blend trees and single states. To be honest i'm not a big fan of blend trees, sometimes tblend trees seem to be the right tool for the right job (for example, mixing stand+crouch with idle+walk+run). However, they have a pretty awful downside: all clips are being played all the time (even if you can't see them in action). This basically means you lose control over the "start time" of the animation. For 1.2.X i had a blend tree for the RopeClimbing state which I ended up replacing with normal states instead, that improved transitions a lot.

    Even if i re-implement this stuff, it won't really matter because (if you are serious about your project) you will probably end up replacing the animator controller, replacing the logic, and so on.

    There is always one state responsible for what is happening at a certain frame (that's the idea behind a FSM). For example, if NormalMovement is active then NormalMovement.cs is responsible for gameplay logic at that particular moment.

    Note that i'm talking about gameplay as a direct result of the FSM internal logic, however, you have to consider the character actor is just another free component (the Animator as well), other monobehaviours could also modify its properties (velocity, size, states, or whatever). In the demo, if the current state is NormalMovement then NormalMovement.cs is responsible for everything.

    Yes, the capsule + CharacterActor should be the base of everything (the camera is optional really).
    The camera is there also to provide that "external reference" used by the state controller. This reference is not required at all.


    Any object that is below the radius (well, not exactly, keep reading) will be walkable by the character.

    You can try two things:

    1 - Play around with the width + ColliderMinBottomOffset values.

    See how fields are validated by the CharacterActor (OnValidate method):
    Code (CSharp):
    1. stepUpDistance = Mathf.Clamp(
    2.       stepUpDistance ,
    3.       CharacterConstants.ColliderMinBottomOffset + CharacterBody.BodySize.x / 2f ,
    4.       CharacterBody.BodySize.y - CharacterBody.BodySize.x / 2f
    5. );
    There is a ColliderMinBottomOffset involved, see if reducing this constant (CharacterConstants.cs) helps. I would recommend something like 0.02 - 0.05, although this will depend also on the width value.
    Please make a backup first.

    2 - Add an invisible wall (affecting your character only --> use layers). Who knows, games are full of tricks, maybe this is the best solution for your particular scenario, maybe not.


    In any case, if you use a vanilla rigidbody + capsule you will get similar results, the capsule will use its rounded bottom part in order to walk over small obstacles.
     
    Last edited: May 3, 2021
    SilverStorm likes this.
  44. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Thanks for the responses yes it's all making sense now!
     
  45. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Hey guys i need some help implementing the AI actions what is the best way to tell the brain to run an action? I've seen the way that you can set it in the GUI of the unity editor but how do I do it from scripts?
     
  46. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, each AIBehaviour has a CharacterActions struct associated with it. In order to change the actions current state you need to modify this struct. For example:

    YourCustomAIBehaviour.cs
    Code (CSharp):
    1. // Moving forward
    2. characterActions.movement.value = Vector2.up; // <0,1>
    3.  
    4. //Jumping
    5. characterActions.jump.value = true;
     
  47. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Hello mate thanks for your response. While I have you is there any way to use the Character Creator Pro with multiplayer / networking
     
  48. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    It really depends on the framework you want to use. The character in this case is a dynamic rigidbody (the controller only modifies its properties prior to the simulation), so if X networking solution is able to "own" the rigidbody over the network, then everything should work as expected.
     
  49. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Hey mate thank you for responding. I have been trying out the asset for quite some time now using the normal movement script that you provided in your demo. a question came to mind is there a way to force an AI character to look a certain direction? i can't seem to get a grip on how the rotation works for the character.
     
  50. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Actions = using input controls (mouse & keyboard, gamepad, etc), trying to rotate a character using inputs can be a very difficult task. The character can be rotated (yaw rotation) towards any direction you want, although this must be implemented somewhere in the logic (your own script, a state, NormalMovement, etc).

    NormalMovement handles rotation in its own way (see the HandleRotation-->HandleLookingDirection method). You can extend this function by setting a "target", for example (i've added a public target transform inside LookingDirectionParameters):

    NormalMovement.cs HandleLookingDirection method
    Code (CSharp):
    1.  
    2. ...
    3. if( !CharacterActor.CharacterBody.Is2D && lookingDirectionParameters.followExternalReference )
    4. {
    5.     targetLookingDirection = CharacterStateController.MovementReferenceForward;
    6. }
    7. else
    8. {
    9.      //...      
    10. }
    11.  
    12. // This part is new
    13. if( lookingDirectionParameters.target != null )
    14.         targetLookingDirection = Vector3.ProjectOnPlane( lookingDirectionParameters.target.position - CharacterActor.Position  , CharacterActor.Up ).normalized;
    15.  
    16.  
    This will make your character look towards that "target" (if not it is not null).

    The AIBehaviour can have a reference to NormalMovement (actions are not everything, remember this is just another Monobehaviour), that way you can change this target at runtime, and still produce actions.[/code]