Search Unity

Character Controller Pro

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

  1. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    I figured as much, but how to I pass a behaviour!
     
  2. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    In the same way you pass any reference object (Monobehaviour, GameObject, Camera, etc ). Here is an example:
    Code (CSharp):
    1. ...
    2.  
    3. //in this case you select the reference using the inspector.
    4. // you can also use GetComponent, or any method you want
    5. [SerializeField]
    6. CharacterAIBehaviour behaviour = null;  
    7.  
    8.  
    9. void Update()
    10. {
    11.        // For example, when you press the F key the behaviour is passed to the brain.
    12.        if( Input.GetKeyDown( Keycode.F )
    13.              characterBrain.SetAIBehaviour( behaviour  );
    14. }
    15. ...
    16.  
    This behaviour must exist in the scene -> added to some GameObject.
     
  3. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    The comment there says it should work with GetComponent, but it doesnt!
    I just have no idea how this works!
    I attached several behaviours to a characterbrain and want to switch between them without having to rewrite the characterbrain class...
     
    Last edited: Dec 26, 2020
  4. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Getting the reference of X component and call its Y method is just pure C#.

    https://learn.unity.com/tutorial/getcomponent#5c8a65d5edbc2a001f47d6e6
    https://learn.unity.com/tutorial/st...e-vs-reference-types#5cef46c0edbc2a261afc8071

    When i say "GetComponent" that means that you don't need to drag and drop your X component into some slot (a.k.a assigning a reference). Many times you would want to go with the "visible reference" approach (e.g. public CharacterAIBehaviour someBehaviour) or just use GetComponent under the hood (the level designer doesn't need to worry about these matters).

    Using GetComponent:
    Code (CSharp):
    1. // not visible in the inspector
    2. CharacterAIBehaviour behaviour = null;
    3. void Awake()
    4. {
    5.        behaviour  = GetComponent<SomeAIBehaviour>(); //<--- assumes the AI behaviour is in the same object containing this component.
    6. }
    7. void Update()
    8. {
    9.        // For example, when you press the F key the behaviour is passed to the brain.
    10.        if( Input.GetKeyDown( Keycode.F )
    11.              characterBrain.SetAIBehaviour( behaviour  );
    12. }
    13. ...
    This is just a new C# script (Create/C# script), you don't need to re-write anything. If you don't create some sort of external script you won't be able to switch between different AI behaviours at runtime (unless you are using visual scripting, playmaker, or something like that).
     
  5. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, the new version (1.2.0) has been uploaded to the store a week ago! unfortunately it is still in review :( ... perfect timing, i guess.

     
    flashframe, Zebbi and filod like this.
  6. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Hi!
    Upon destroying physical objects at runtime I get this exception:

    MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UnityEngine.Object.get_name () (at <fe84f4a754da4a6bb64fca409d40938a>:0)
    Lightbug.CharacterControllerPro.Core.CharacterActor.ToString () (at Assets/Character Controller Pro/Core/Scripts/Character/CharacterActor.cs:508)
    Lightbug.CharacterControllerPro.Core.CharacterDebug.Update () (at Assets/Character Controller Pro/Core/Scripts/Character/CharacterDebug.cs:44)

    Any idea whats going on?
     
  7. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Looks awesome! Do you have an early changelog we could see? ;)
     
  8. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, sorry i missed that! I believe behaviour designer lets you create your own task.

    This -> https://opsive.com/support/documentation/behavior-designer/tasks/

    Maybe you can define a task that switches between AI behaviours or modifies the actions directly (version 1.2.0).
    Thanks! version 1.2.0 should be available now. here are the release notes.

    Hi, that happens because the character is destroyed but the Debug component is still asking for that specific character actor. Sorry, i forgot to check for the character actor!

    Fix:
    Modify CharacterDebug.cs Awake and Update methods:
    Code (CSharp):
    1.  
    2. void Awake()
    3.     {
    4.         if( characterActor == null )
    5.         {
    6.             this.enabled = false;
    7.             return;
    8.         }
    9.    
    10.         if( debugCollisionFlags )
    11.         {
    12.             if( text == null )
    13.                 this.enabled = false;          
    14.         }
    15.    
    16.     }
    17.  
    18.     void Update()
    19.     {
    20.         if( characterActor == null )
    21.         {
    22.             this.enabled = false;
    23.             return;
    24.         }
    25.    
    26. ...
    27.  

    If you don't need this debug component you can remove it from the scene, if not then add the code i wrote. I'll fix this in 1.2.1, thanks for letting me know!
     
  9. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Hi again!
    I'm once again trying to tackle the ladders.
    I know you said you don't support these examples, but I still dont know where else to turn...
    I did buy this component thinking it would support these basic interactions and writing my own ladder climbing is obviously way over my head.

    I dont understand why it doesnt use the gizmos of up/down. The animation is always the same height no matter where I place the gizmos.
    I dont understand why the animation controller for ladder climbing contains no animations except the exit animations.
    I dont understand why in the animation transitions no triggers are ever set.
    All the states are empty and contain no animations.

    Even studying the script in all detail, I just dont get where it gets any of its information from. it should get the targetposition from the gizmos, but it obviously doesnt! what can I do to tune the ladder climbing?
     
    Last edited: Dec 31, 2020
  10. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    I'm not sure if you know how root motion works. In any case, I'd recommend you to check the documentation (Unity's docs are meh, especially reagarding root motion). This is Unreal's root motion -> https://docs.unrealengine.com/en-US/AnimatingObjects/SkeletalMeshAnimation/RootMotion/index.html (far better IMO).

    All states contain animations, they are not empty:
    -TopUp
    - TopDown
    - BottomUp
    - BottomDown
    - Idle
    - Up
    - Down.

    First, check the transitions in the animator controller.
    The script reads inputs and then sets triggers (based on those inputs), that's all it does. The state is 100% root motion, there is no target position, variable ladder/step height or something like that, only the number of iterations for the climb animation (up or down).
    Code (CSharp):
    1.  
    2. ...
    3. if( CharacterActions.movement.Up )
    4. {
    5.            if( currentClimbingAnimation == currentLadder.ClimbingAnimations )
    6.            {
    7.                   CharacterStateController.Animator.SetTrigger( topUpParameter );
    8.            }
    9.            else
    10.            {
    11.                   CharacterStateController.Animator.SetTrigger( upParameter );
    12.                   currentClimbingAnimation++;
    13.            }
    14. }
    15. ...
    16.  
    If you want to climb up (up input) and the current "iterator" is equal to the max value (ClimbingAnimations) then start the TopUp trigger. If not, set the climb trigger, and increase the iterator.

    Doing a "match target" will produce "foot sliding" (if you use some arbitrary destination), something you don't want when using root motion. The ladder should be made for your specific animation, this is not a procedural ladder climbing system (e.g. An IK based system).

    You can:
    - Change the animations for the ones you want (and adjust the ladder model based on those clips).
    - Modify the triggers. The Top and Bottom objects are triggers, invisible objects that start the ladder climbing state (Top or Bottom).
    - Modify the number of steps for X ladder in particular.
     
    Last edited: Dec 31, 2020
  11. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Hi!
    But I'm changing the top and bottom objects... it does nothing, the animation always ends at the same spot no matter where I place the top object!
    I havent seen where you can adjust the number of steps, maybe thats my missing part...
     
  12. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Ok I see now that the number of cycles determines how high up the climb goes.
    Still not what I read form the script, where I can clearly see it takes the location of the top gizmo and places the character there, but ok.

    Now the next problem is still, I dont understand the animator. It is a state definition with NO animations in it. The inspector shows every state and every transition completely empty, except the last two, which I assume are not root animations.

    Where do the animations come from? Where do I adjust and change them?
     
  13. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Last edited: Jan 1, 2021
  14. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    So I see now that it would be quite hard to change into the ladder state anywhere on the ladder.
    I will drop this idea for now, but I would ask one last thing:
    Is there an easy way to cancel the ladder climb with a jump?
     
  15. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, Happy new year!


    That's all triggers do, they start the ladder climbing state. They do not specify a target destination or something like that, all displacement calculations come from the animation clip itself. This is why animation and ladder design must be "in sync". In other words, CCP Demo's animations work only with CCP Demo's ladder (step distance, i'm not talking about the model).
    Also remember this is just a demo state that showcase how root motion works, nothing more. Many users have modified the state parameters (values, animation clips, etc ) and/or code to suit their own needs.

    Oh yeah, 2020.1 was a disaster, i don't recommend it at all. 2019 LTS or 2020.2 (although i always prefer an official vers...i mean, a LTS version ;))

    There is a forceExit bool inside LadderClimbing. If you take a look at the code, you'll notice that if you press "interact" (Started) while being "idle" you can abandon the state (forceExit = true). Chage "interact" for "jump".
     
  16. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Thanks! that will do nicely for now!
     
  17. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    Hey!

    So, not gonna beat around the bush; doubting whether to get this or KCC. Both seem very capable but there is one thing that I wonder about, and one I see in KCC that I wanted to ask about for CCP :)

    So, if you stand on a fast moving platform and you press jump, you just jump up. The inherited velocity from the platform is neglected. I would expect to be launched in the moving direction of the platform instead. This is what I like in KCC, but possibly this is also working in CCP but just not in the demo scene? Is this correct?

    Secondly, the pushable RB option... in KCC I see it clipping the character and not in CCP so yeah that's great, thumbs up. However, if you jump up and push the RB at the top, it will never topple over but just slide out of the way. Is this something that could work or is the nature of the controller such that it is pretty impossible?

    upload_2021-1-3_21-9-36.png

    Thanks for answering and keep up the good work!
     
  18. shanemt

    shanemt

    Joined:
    Mar 5, 2014
    Posts:
    23
    Hi, I'm not sure where to file bugs. I'm modifying the Demo Character 3D prefab, and inside of CharacterStateController.Awake(), the last line calls AddAndInitializeStates(). This calls LadderClimbing.Initialize(), which uses a reference to LadderClimbing.CharacterStateController. The problem is that the reference to CharacterStateController is set inside of LadderClimbing.Awake(), and there's nothing guaranteeing that LadderClimbing.Awake() is called before CharacterStateController.Awake(). So upon swapping out the prefab's model, I randomly started getting null reference exception.

    I was able to fix it by moving CharacterStateController.AddAndInitializeStates() from Awake() to Start(). You could also solve this issue by modifying the execution order of the state scripts, but the using Start() instead is the better solution. One last thing is that it's typically not ever a good idea to use references to other objects in Awake(), just set references and make self modifications. Then in Start(), make use of the references and do whatever initialization that object needs.
     
  19. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi there!
    Thanks for reporting this (and for the detailed info), for bug reports i always recommend to use support (e-mail).

    A "source (out of) control" issue :(
    This is caused (believe it or not) by me trying to integrate the new character actor component (some of it) from 2.0.0 back into 1.1.5 (->1.2.0). "Initialize" was removed from the CharacterState component in 2.0.0. Issue: 1.1.X wasn't using git back then, so I had to keep track of a lot of changes "by hand" (Trello).

    I agree with you, changing the execution order is not pretty, i prefer the Start method, in fact that's what i did before in my internal version.
    If you want to fix this bug (i know you already fixed it) you can:
    Code (CSharp):
    1. // change
    2. public virtual void Initialize()
    3.  
    4. // with:
    5. protected virtual void Start()
    6.  
    7.  
    This will cause some errors (of course). CharacterStateController.cs (AddAndInitializeStates):
    Code (CSharp):
    1. states.Add( stateName ,  state );    
    2. // state.Initialize(); <--- Delete
    3.  
    There are three states that use "Initialize" and/or "Start": LedgeHanging, LadderClimbing and NormalMovement:
    Code (CSharp):
    1. protected override void Start()
    2.     {
    3.         base.Start();
    4.             ...
    5.    
    6.     }
    In NormalMovement.cs there is no "Initialize", however there is a Start (a warning).

    I have uploaded 1.2.1 already! damn it. I'll upload the patch (1.2.2) soon.

    Hi, yeah i'm well aware of that, other users have asked me the same thing. I didn't have time to include just another feature to the character when releasing 1.2.0 (it was a lot), so i decided not to include a that.

    It will be there of course.

    This time i did introduce that :) (the code is doing its thing), however i think the demo scene wasn't really prepared for that. Some of the boxes are freezed (rotation), that's why the interaction (in the air) feels a little odd. Also most of them have a high mass (comparable with the character). If you are stable you can push over and over again a certain object, on the other hand, while being not stable (e.g. in the air) you will slide + push the RB (1 frame). That's why the effect is not the same (stable vs unstable) since the character cannot provide a constant velocity to the affect body. This might change in the future (more options).

    Here is a little demo, this time no drag, no constraints:
    PushRB.gif

    So, maybe this is my fault.

    ------------------------------
    The reason why a kinematic CC does that (i'm not talking specifically of KCC the asset) is because interacting naturally with rigidbodies is tricky (not perfect). CCP was originally a Kinematic CC (while being in development), that's why it was easy for me to combine predictability (KCC) with rigidbody interactions (DCC).
     
    Last edited: Jan 6, 2021
  20. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    Thanks for your reply, pretty much answers it all. If you will incorporate/'fix' the platform velocity then I'm happy! As for the RB interaction: I kinda figured it has something to do with constraints but couldn't check it without buying ;) I guess you have a new customer, eager to try it out. Demo was pretty impressive!
     
  21. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Hi!
    I'm trying too implement a pooling solution.
    As an actor gets disabled, I get this error:

    MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    Lightbug.CharacterControllerPro.Demo.MaterialsProperties.GetVolume (UnityEngine.GameObject gameObject, Lightbug.CharacterControllerPro.Demo.Volume& outputVolume) (at Assets/Character Controller Pro/Demo/Scripts/Materials/MaterialsProperties.cs:82)
    Lightbug.CharacterControllerPro.Demo.MaterialController.GetVolumeData () (at Assets/Character Controller Pro/Demo/Scripts/Materials/MaterialController.cs:157)
    Lightbug.CharacterControllerPro.Demo.MaterialController.FixedUpdate () (at Assets/Character Controller Pro/Demo/Scripts/Materials/MaterialController.cs:206)

    It doesnt seem to break anything, but I still wonder what I can do to avoid it!
     
  22. shanemt

    shanemt

    Joined:
    Mar 5, 2014
    Posts:
    23
    Thanks for the feedback Lightbug.

    I have another question actually. How would it be recommended to implement a crawl state in regards to the collider? I can't just make the capsule have a bigger radius to accommodate for the increased length since the character is on his side, because he's not getting wider as well.
     
    Last edited: Jan 5, 2021
  23. SimplyNew

    SimplyNew

    Joined:
    Jul 21, 2020
    Posts:
    9
    Hi @lightbug14,

    I am using CCP in 2d side scroller. I am facing two issues currently. Can you please help?

    1. Vanilla Rigidbody 2d based platform doesnt really work for me. I have a simple floating platform, moved left, right using Dotween. I am moving it using rigidbody move. But, Character doesn't really stay on platform, it floats over platform and platform moves away. I know, you have mentioned, the behavior of Vanilla RigidBody is not perfect. But, I would like to know if this should have worked. I have many platforms already created using this approach and changing all would take lot of time. I dug up into code and in ProcessDynamicGround(), I checked incoming "position" vector and after displacement calculation, position vector remains the same. I have tried moving platform in update, fixedupdate, late. All of them gives same behavior. I also tried with keeping script execution for this platform ahead of CharacterActor.

    2. I think, I may have found bug. jumpInertiaMultiplier of VerticalMovementParameters is not used anywhere. So, it doesn't do anything. May be this is WIP item.

    Thanks
     
  24. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, you are saying "disabled", but the console clearly says "Destroyed". Who is lying? :D
    I'm not getting that on 1.2.1 (should be avaialble now).


    Hey, thank you! I'll probably include some more stuff regarding RB interactions in general.

    Hi, thanks for sharing that! In fact i'm very interested in getting feedback about these topics.
    The reason why i keep using this approach (for 1.x.x at least) is because:
    1. This was introduced in 1.0.0 (i think), much of the gameplay logic (Demo) depends on actions (states, state controller, AI, etc.). In 2.0.0 this will be improved (the implementation in general will be the focus).
    2. it works in a very similar way (not technically speaking) to the new input system actions classes, that is, actions are represented as fields that you can access in compile time (they are thightly coupled with the class). This is a nice and fast approach (compared with using strings, e.g. mecanim), however "tightly coupled" does not sound good in programming.

    So, even though i knew this system was not perfect, i felt that it was "ok", especially if you want to create something yours by ignoring or modifying the demo states (which is what you should be doing anyway).

    I'm not sure if i understand exactly what you are proposing about the more granular system. A factory pattern will work well for runtime operations ("newing" things up on the fly). I don't believe this pattern can replace 100% the current approach (maybe i'm wrong, please let me know).

    For 2.0.0 I tried messing around with interfaces and generics in order to achieve some abstraction. However, Unity was always in the middle, serialization, inspectors, editors, generics and interfaces, Unity just does not like them at all.

    Yeah, that would be really nice, something like the action maps from the input system.

    At the end of the day i'm trying to replicate the new input system actions. The reason why i don't delegate all the work to this system is because Unity does not let you modify actions directly (you must use events and tricks to simulate this). Also the inspector part is very important for me.


    ---> I will answer the rest ASAP...
     
  25. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hmmm that's a really common problem with upright capsule controllers in general. There are tricks you can use to simulate that, for example many games use a circle shape (i know, this is far from perfect), however you can get away with that depending on the case (for example: swimming state » not many collisions » less noticeable). The circle can be placed close to the head (not necessarily at the center). Integrating a "horizontal capsule" based character (2D uses this term) is something i always wanted.

    Sorry, this is because i'm writting the platforms "how to" section as we speak. In the demo scenes kinematic/dynamic platforms use the RigidbodyComponent component. Is it possible for you to convert that Dotween movement into RigidbodyComponent's Interpolate/Move/Velocity?. See how ActionBasedPlatform does this:

    Code (CSharp):
    1.  void FixedUpdate()
    2.     {
    3.         float dt = Time.deltaTime;
    4.  
    5.         Vector3 position = RigidbodyComponent.Position;
    6.         Quaternion rotation = RigidbodyComponent.Rotation;
    7.  
    8.         movementAction.Tick( dt , ref position );
    9.         rotationAction.Tick( dt , ref position , ref rotation );
    10.  
    11.         RigidbodyComponent.MoveAndRotate( position , rotation );
    12.     }
    Unity doesn't expose any pre-simulation information about the RB, so without using some sort of wrapper it is impossible for the character to know if the ground is going to move (i'm talking about point velocity) in FixedUpdate (this applies also to kinematic platforms). This is why many character controller solutions use their own character vs platform little system.

    Yeah i totally missed that! Thanks for letting me know.
     
  26. guitarguruu

    guitarguruu

    Joined:
    Jun 6, 2020
    Posts:
    11
    Using this asset and I had it up and running last night when I went to bed, but now when I opened the project today I get a console error stating:

    NullReferenceException: Object reference not set to an instance of an object
    Lightbug.CharacterControllerPro.Demo.LedgeHanging.Initialize () (at Assets/Character Controller Pro/Demo/Scripts/States/LedgeHanging.cs:106)
    Lightbug.CharacterControllerPro.Implementation.CharacterStateController.AddAndInitializeStates () (at Assets/Character Controller Pro/Implementation/Scripts/Character/States/CharacterStateController.cs:223)
    Lightbug.CharacterControllerPro.Implementation.CharacterStateController.Awake () (at Assets/Character Controller Pro/Implementation/Scripts/Character/States/CharacterStateController.cs:155)

    Any solutions for this? I haven't changed a single thing since last night when it was working before saving and closing the project.
     
  27. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi @guitarguruu , please read this post, this is actually what i'm doing for 1.2.2 (next patch). In any case, don't worry about the error itself, "Initialize" doesn't do anything relevant (demo content POV), so the behaviour should be exactly the same.

    I'm not sure why this is happening now, the "Initialize" method has been around since 1.1.0 (i think).
     
  28. guitarguruu

    guitarguruu

    Joined:
    Jun 6, 2020
    Posts:
    11
    Thanks for the quick reply. I tried reimporting and it functioned but upon closing and reopening the project the error persists although a bit different this time:

    NullReferenceException: Object reference not set to an instance of an object
    Lightbug.CharacterControllerPro.Demo.LadderClimbing.Initialize () (at Assets/Character Controller Pro/Demo/Scripts/States/LadderClimbing.cs:212)
    Lightbug.CharacterControllerPro.Implementation.CharacterStateController.AddAndInitializeStates () (at Assets/Character Controller Pro/Implementation/Scripts/Character/States/CharacterStateController.cs:223)
    Lightbug.CharacterControllerPro.Implementation.CharacterStateController.Awake () (at Assets/Character Controller Pro/Implementation/Scripts/Character/States/CharacterStateController.cs:155)

    Going to attempt to do the fix you mentioned, but otherwise this will be fixed in a patch yes? I wouldn't worry about the error but with the error currently my character controller is not functional so can't do any testing or anything haha.
     
  29. shanemt

    shanemt

    Joined:
    Mar 5, 2014
    Posts:
    23
    I will definitely let you know if I come up with something clean, thanks!

    Yeah I can see why it's a tough problem to solve. A hacky way I was thinking about handling it was to:
    1. Shrink the height of the capsule collider accordingly.
    2. Enable two additional short capsule colliders & rigidbodies as child objects of the player, in front of and behind him.
    3. Have the player's collider push and pull these things around, and if the front or back collider can't go through something, then neither will the player be able to because he'll be running into them and they can't move.
    It might work. Who knows?

    _______________________________________________________________

    I'm running into another problem that I can't figure out . I feel like I'm gonna be filling up this forum with a lot of posts! But I really like the asset so this is no knock against it, best I've ever used and a great framework.

    I can't remember exactly what the steps were to cause the issue because I only started seeing it once I clicked on the game object that hosts the CharacterBrain. The custom editor extension on CharacterBrain is throwing a bunch of exceptions and won't show any of the actions. I don't see any problems in CharacterBrainEditor and debugging isn't really shining a light on the problem.


    Turns out what happened is that because I didn't like that BoolAction.value was lowercase (since it's public), I ended up Ctrl+r+r renaming it to BoolAction.Value and didn't realize it was referenced by string in the custom unity editor code in BoolActionEditor. Same for FloatAction/FloatActionEditor and Vector2Action/Vector2ActionEditor so this was causing CharacterBrainEditor to blow up, and it took me a while to figure out where the problem was coming from.

    A trick I've used to prevent this sort of problem is to create an instance of the struct in the editor, and refer to the field on the instance of the struct, and use the nameof operator to get the string. That way it doesn't break if variable names change. And if you delete the property you're referring to by string, then the compiler will throw an error.

    i.e.,

    Code (CSharp):
    1. [CustomPropertyDrawer( typeof( BoolAction ) )]
    2. public class BoolActionEditor : PropertyDrawer
    3. {
    4.     private BoolAction boolAction;
    5.  
    6.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    7.     {
    8.         EditorGUI.BeginProperty( position , label , property );
    9.        
    10.         SerializedProperty value = property.FindPropertyRelative(nameof(boolAction.Value));
    11.        
    12.         ...
    13.     }
    14. }
    15.  
     
  30. bunnybreaker

    bunnybreaker

    Joined:
    Dec 10, 2013
    Posts:
    23
    Hey, loving the 1.2 update. It works even better in my game than before.

    I do have a request though. Can you make the variables and methods in the demo states protected? It'd make it a lot easier to inherit from those classes without breaking when updating your asset.
     
  31. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Yes, the new patch should be available soon :)

    Well, naming conventions can be a little flexible sometimes (i know, it is supposed to be a "convention"). For instance, with private fields you need to use "_camelCase" or "m_camelCase", however this is kinda awful nowadays (i was a C++ "m_" fanboy in the past). I think almost everyone use camelCase for private fields. Regarding public fields i didn't know pascal case was the standard, interesting, i guess i could adapt to that in the future. You still have a problem with protected fields, Do you treat them like public or privates?

    Hi, great! :) Yeah sure no problem (added to my trello).
     
  32. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    Hey!

    I'm trying out Root Motion but I must be missing something. Maybe you could explain briefly what I'm missing?

    I made a CharacterState and it only does this:

    Code (CSharp):
    1.  
    2.     public override void EnterBehaviour(float dt, CharacterState fromState)
    3.     {
    4.         targetLookingDirection = CharacterActor.Forward;
    5.         CharacterActor.alwaysNotGrounded = false;
    6.  
    7.         CharacterStateController.UseRootMotion = true;
    8.     }
    9.  
    10.     // Write your update code here
    11.     public override void UpdateBehaviour( float dt )
    12.     {
    13.         float gravityMultiplier = 1.0f;
    14.         float gravityMagnitude = 10f;
    15.  
    16.         float gravity = gravityMultiplier * gravityMagnitude;
    17.  
    18.         if (!CharacterActor.IsStable)
    19.             CharacterActor.VerticalVelocity += -CharacterActor.Up * (gravity * dt);
    20.     }
    21.  
    And on my character I only have one Default State on my Animation Controller: Walking which has a Walking animation, obviously, with root motion from Mixamo (so not in place).

    Now... if I play my scene, the character will walk straight and then will not fall off a high ledge but will float down slowly. Like a feather if you will... if i disable the line where VerticalVelocity is changed, she walks straight on. So there is something happening but not what I expected.

    I could make step down distance really large but it's not intended that way I think, so yeah.

    upload_2021-1-7_23-57-24.png

    But if I let the character walk towards a minor step, the controller will move up and then move down again. I just find it weird that it sometimes works and sometimes doesn't. Maybe because the step-mechanic is different and is done in the controller itself?

    upload_2021-1-8_0-2-3.png

    I'm guessing this is because I should play a 'falling' animation which will translate the character (root motion) if the distance is much larger than the step down size...? Other solution is disabling root motion I guess while the controller 'falls down' but I haven't figured out how those steps would work.

    And with the danger of asking too much: how do you see an implementation of when you reach a step that you can play a step up animation?

    Maybe you could elaborate? It's not so much a flaw in CCP but I'm learning. I really like root motion :)
     
    Last edited: Jan 8, 2021
  33. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    224
    how to do oneWayPlatform and JumpDown in 1.2.1 ?
     
  34. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Hi! I have a question:
    I'm unable to attach objects to my characters bones, they just dont animate. Research has told me that I need to activate Root motion on the root object for this to work. If I start up the game, root motion flag disappears and gets replaced with "Handled by script".
    Is this related to the character controller or do I need to search elsewhere?
     
  35. SimplyNew

    SimplyNew

    Joined:
    Jul 21, 2020
    Posts:
    9
    Hi @lightbug14

    I have one request. Can you please make CharacterActor's SlopeLimit public or provide setter method? I have one use case where temporarily, I want to change characters slope limit. I have tested by updating this limit in game mode from editor, it works fine without any side effect. If you think this values shouldn't be changed dynamically, please, let me know any other way to achieve this. Currently, I have just added setter. But, upgrades to future versions unnecessarily be affected just because this small change.

    Thanks
     
  36. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Anyone who does not see the newest scene demo there is a bug with the package manager lying about what you got installed. Delete the package from your project and from the roaming folder and downloaded a new one and you will have the latest version.

    Also @lightbug14 this new update has removed a fair number of tags and layers. Any explanation on this?

    Also I am wondering if there's anyway to make the way the camera collision better.
    For example if I jump on a ledge from side ways the camera will zoom in suddenly and you won't see the player hanging off the ledge.

    I have uploaded a video to demonstrate. I can also jump over the ledge and hug the wall and it will go through the player. That one isn't as bad but still....can it do better?

    His hands also clip through the wall but I wonder if this is just animation related?
     

    Attached Files:

    Last edited: Jan 10, 2021
  37. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Yeah that makes sense, it will be in version 1.2.2 (it should be available really soon). Everything is public, slope limit, step up distance, step down distance, etc etc etc.

    One way platform was never a thing in CCP. If for some reason this worked, it was a "side effect" (i'm talking about platform effectors). The process is really simple:
    • if the character is ascending then ignore "OWP layer".
    • If the character is falling + there is no overlap with a OWP ("OWP layer") then include the layer as a valid collision layer.
    You have the PhysicsComponent component which allows you to use IgnoreLayerCollision (2D and 3D), this is how i do it.
    The reason why i didn't include OWP as an official feature (for 1.2.0) is because i didn't test it enough (and because there was a lot introduced in that version).

    That "handled by script" means there is a script (AnimatorLink from CCP) that links the Animator object with the character state controller. If you will be using this state controller, this is required for root motion. Activating root motion needs to be done using this component:
    Code (CSharp):
    1. CharacterStateController.UseRootMotion = true;
    Root motion in CCP does not let the rigidbody to move, instead it extracts the motion from the clip and then re-applies it into the character actor.

    I think that's because root motion is defining 100% of the movement. Velocity (vertical in this case) doesn't matter, maybe you can try to disable root motion when the character is unstable.
    I guess the feather effect is caused by a conflict between gravity (vertical velocity) and no vertical displacement from the clip. This also happens when you set rb.velocity = 0 and useGravity = true (default rigidbodies).

    Yes, most of them are useless now. Before 1.2.0 you needed to assign dynamic rigidbodies using a layer (which was crazy), also triggers didn't need a dedicated layer (the collision process filters those anyway).

    Putting less extra content inside your project (tags, layers, inputs, etc) is always good. That's (for example) why i use the default "UI" layer (i think) for the "not pushable" object in the demo :D.

    That's weird, i don't get that behaviour (hands + camera). Maybe you changed the size (?). In any case, i'm experimenting with "MatchTarget" to get better results (animation ). Regarding the camera, try to reduce the radius from the sphere cast (Camera3D -> detectionRadius), this might help.

    Also, the ledge idle animation clip was missing from the Animator :oops: Maybe this happened while separating all the animations into different assets (probably). This is fixed in 1.2.2, however, if you are using 1.2.0 or 1.2.1 you can fix this by assigning the clip manually (open LedgeHanging animator controller, go to idle and select the clip).

    ───────────────────────────────────────────────

    The new version fixes some relevant bugs, i would recommend to update to 1.2.2 as soon as possible (still in review). Some of these issues:
    - The character started floating from bottom to idle (animation), this was caused by "force grounded at start" not doing its job.
    - The "Initialize" error mentioned a couple of days before.
    - Dynamic ground velocity coming from nowhere.
    - and more...
     
  38. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Okay so.
    I want to make platforms that appear and disappear.
    Destroying an action based paltform makes all of CPP crash irreversably.
    So I can't use destroy.
    Instead I try to disable the action based platform.
    However, when the character is standing on the platform as it gets disabled he is teleported to world origin?
    Help!
     
  39. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Oh yes and I have a feature request:
    You can define surfaces like ice and grass that affect how you move.
    I really need a surface (not a field) that allows me to disabled jumps! Do you think that would be possible?
     
  40. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    With the external reference on the State Controller, is there an easy way to update the looking direction as soon as the camera is rotating? So the looking direction is always the camera forward vector? And the character rotates accordingly?

    Like in Assassin's Creed: Odyssey for example., you move the mouse around and the character will begin to move/rotate in that direction, not only when moving forward.

    Thanks!
     
  41. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    I'll check that, thanks for reporting that. If you have bugs to report please send me an email with all the details, that's the official way to do it. Most of the bugs posted here are fixed eventually, however i consider the forum thread more like "discussion" rather than "support". By using the mail you are helping me to keep everything organized.

    There are two ways:
    1. In your state (or whatever logic component you are using) check the ground object, if this object is the object you want (tag, layer, component, etc ) then disable the jump (e.g. if you are using NormalMovement, find "canJump" and turn it to false).
    2. Similar to 1, in this case you will be disabling "canJump" from an external component (e.g. a trigger).

    I have made jump pads in the past using approach number 2. The jump pad calls ForceNotGrounded and gives the character a vertical velocity.

    Do you mean NormalMovement -> LookingDirectionParameters -> FollowExternalReference (bool) ?
     
  42. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Me again, forget what i said before. While i was trying to reimplement OWP using the "new" CharacterActor (from 1.2.0) i remember all the issues related to this feature. I did finish OWP + JumpDown, here is a video:


    Implementing this (by your own) will be tricky, i'm disabling specific collisions (collider A vs collider B) depending on the one way platforms layer mask.
     
    filod likes this.
  43. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    224
    i indeed made a simple OWP which use "IgnoreLayerMaskCollision", are you going to release your OWP ?
     
  44. pez

    pez

    Joined:
    Jul 6, 2013
    Posts:
    52
    Hi, I just got the controller yesterday & it's great!

    Just wanted to check to see if you ever implemented 'acceleration tilt' as an optional feature yet?
    I took a look through the documentation & searched this thread & saw someone else had suggested it a while back.

    Here's a link to the reference again https://www.gdcvault.com/play/1020583/Animation-Bootcamp-An-Indie-Approach (5:05)
    I also noticed it playing around with cubeworld

    It's definitely something I'd like to implement over just having the animation lean them forward, which wouldn't take into account camera turns driving the motion which is pretty key I think.

    I've tried to implement this thing before but the maths behind this is way over my head so hope that it's something you can add in!

    Thanks,
    Pez
     
    lightbug14 likes this.
  45. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Yes i'll release it (1.3.0 i guess).

    I'm asking myself how should i implement this feature (the final version of it), i'm struggling between two different approaches: IgnoreCollision vs IgnoreLayerMaskColliison (my own implementation, unity doesn't include this).

    Approach A (IgnoreCollision):
    In the current implementation i use IgnoreCollision (collider A vs collider B), the cool thing about this is that you can assign any layer you want with to the character. To explain this a bit more, imagine three objects a Character, a Box (dynamic RB) and a one way platform (OWP):
    Character = "Default"
    Box = "Default"
    OWP = "One Way Platform"


    By using this approach characters will ignore each OWP on demand, meaning that the layer itself ("Default" in this case) as a whole will not be affected at all. The box vs OWP collision will work as expected (default vs default).

    Approach B (IgnoreLayerMaskCollision):
    On the other hand, if i use IgnoreLayerMask, then the whole layer will be affected, which can be good (there is one case where approach A fails) or bad (other objects from the layers will be affected) depending on the scene settings.
    By using this approach characters require a dedicated layer, for example:
    Character = "Character"
    Box = "Default"
    OWP = "One Way Platform"


    I'm trying to improve this by creating a mix between the two approaches, let's see how it goes.

    Hi, thank you very much!

    Yeah, acceleration tilt has been requested before (really cool effect). i have something going on, however it is very buggy at the moment :(. It includes acceleration and velocity tilt.
     
  46. carmofin

    carmofin

    Joined:
    May 13, 2017
    Posts:
    116
    Now I can work around the Destroy issue. But the Disable problem really breaks my neck!
    I was hoping you would have an idea on how to fix it!
     
  47. pez

    pez

    Joined:
    Jul 6, 2013
    Posts:
    52
    Thanks for responding so quickly!

    Look forward to seeing it included, & let me know if you want any outside testing/feedback on it prior to that!

    Thanks,
     
  48. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    224
    i met an nasty bug that: character will continue *slide up* slope at a very very low speed (without input)...`stableProbeGroundVelocity`/`PostSimulationVelocity` also gives wrong result (which i used for animation params), this problem only appears in my project not CCP's demo scene.. really frustrated, can you give some hint ?

    (maybe useful: when i disable "prevent bad step", the character penatrate slope collider which he shouldn't)
     
    Last edited: Jan 14, 2021
  49. Emphy

    Emphy

    Joined:
    Feb 7, 2014
    Posts:
    33
    I use the NormalMovement state for now, yes. And my external reference is my (ootti) Camera Controller object. It's set to rotate the camera on mouse move. Now, if I press forward (w) the CCP will move my character in the direction the camera is looking at gradually (I guess that's a Lerp) but I want the CCP to always look in the direction of the camera. So moving mouse left, character turns to the left immediately (albeit smoothed), without delay.
     
  50. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    224
    i found ccp will penetrate walls when in high speeds, my solution is set `RigidbodyComponent.ContinuousCollisionDetection = true`, don't know why this happen...