Search Unity

Character Controller Pro

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

  1. artician

    artician

    Joined:
    Nov 27, 2009
    Posts:
    341
    Did you happen to find a solution to this? I'm also a PlayMaker-centric developer and ran into the same struct-related problems.
     
  2. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    676
    Using Behaviour Designer I was able to setup a basic patrol for an enemy and have them chase and attack the player.
    Now the next step is for me to get the character controller to strip away the unnecessary animator states and extra features like crouch and dash and then somehow put the attack state and animation in hopefully without hassle.

    What's the best way to do that?
    My guess is to use the character in the "Character Scene" [Performance Demo Character?] and convert it into a prefab because it has no animations and most extras are stripped.
    Then in the Normal Movement component disable the crouch. There's no dash I think so I don't need to touch it unless it's hidden in there somewhere.
    There are no animations on that character so I would assume for safety I would still uncheck the "override animation controller" setting and then I should be ready to go right?

    Then what steps would I need to begin to get my custom inputs and animations working smoothly with it without breaking anything for example I would add so on mouse click they attack an enemy and have them animate the upper part of their body only so they can attack while in air and on the floor are there any extra steps I need to consider because of the CCP or is this easier than I think?

    Bit of fun here you can see the enemy AI video I have:
    https://1drv.ms/v/s!AjhzZ7qjdmSBhBkWk2LjIBixHsfq
     
    Last edited: May 10, 2021
  3. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    50
    Hi @lightbug14,

    I'm having an issue with getting my character strafing around a target. The camera is a fixed perspective, I have the player rotating to continually face the target without issue, but I want the movement to always be relative to the camera. That is as the rotate around the target the player needs to change the input direction. Eg when they are below the target they would push w to move towards, when they are on the left of the target they would push d to move towards it, etc.

    Any help you can provide would be good.
     
  4. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    676
    To get your movement based around the camera in the "states" game object you will see a character state controller component and on it you will see in big writing the Movement Reference Parameters. Drag the Camera into the external reference and your movement should now be based on the camera. If you want your movement to be based on a different object like your strafe target then drag your strafe target into that slot and now your movement should be based around it.

    Is that what you were looking for?
     
  5. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    50
    @SilverStorm, I've tried both of those, and neither are working for me. I'm sure I'm missing something but can't see what presently. If I set the strafe target should it be based on the direction between the player and the target or the current rotation of the strafe target?
     
  6. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    676
    I will just throw a mash of stuff at you maybe it will help otherwise you can wait for Lightbug to answer.

    Your movement should be based on the strafe targets transform either local transform or global transform.

    You can see a tutorial on how to rotate around something here but I'm not sure if it will apply to the CCP here:

    In that example your movement should be based on input direction so left input would move it on the X minus while right input would move it on the X plus and similar for Y axis if you are jumping or in the air.

    There is also more if that doesn't help as there is an example scene you can check out in CCP called the Zero Gravity scene that may have what your looking for because the character can move all crazy in the air up and down and you can rotate the view, strafe etc.
    And extra tip if you want to convert a transform from local to vertical for the camera they use TransformDirection in the scripting API.
     
  7. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    50
    Thanks, I think I need to use the Character option on the CharacterStateController but then modify that input value by the direction of the camera, or use the camera as external then modify that by the character direction.

    Just haven't got it working yet.
     
  8. Mythran

    Mythran

    Joined:
    Feb 26, 2013
    Posts:
    76
    Hello,
    How would one into auto-crouch by detecting the height above is less than 2.0f, or top of collider is hit?
     
  9. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    50
    Depends on how often you'll use it. If its only a few times, I just have a trigger collider in the few locations. Otherwise I'd probably check from the fop of the collider
     
  10. Mythran

    Mythran

    Joined:
    Feb 26, 2013
    Posts:
    76
    Code (CSharp):
    1.  
    2. private void OnTriggerEnter(Collider other)
    3. {
    4.     RaycastHit hit;
    5.     if (Physics.Raycast(startPoint, startPoint + Vector3.up, out hit, Mathf.Infinity))
    6.     {
    7.                 float height = hit.point.y - startPoint.y;
    8.  
    9.                 if (height > 0.8f && height < 1.0f)
    10.                 {
    11.                         crouch = true;
    12.                 }
    13.      }
    14. }
    15.  
    or

    Code (CSharp):
    1. {
    2. RaycastHit hit;
    3.     if (Physics.Raycast(playerFeet, playerFeet + Vector3.up, out hit, Mathf.Infinity))
    4.     {
    5.            float height = hit.point.y - playerFeet.y;
    6.  
    7.            if (height > 1.5f && height < 2.0f)
    8.            {
    9.                   crouch = true;
    10.            }
    11.      }
    12. }
    Well i was asking more for a code snippet to see if it can be as simple as this...
    But thanks.
     
    Last edited: May 13, 2021
  11. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    50
    Hi,

    Is there a way to go back to the previous state without know what it was? Eg I have a state that I want to go into then back to the previous one not to a default one.
     
    Last edited: May 20, 2021
  12. Mythran

    Mythran

    Joined:
    Feb 26, 2013
    Posts:
    76
    Yes it is possible, 15:50 starts the implementation of the previous state.
    Just call the previous state instead of calling a specific state.


    Regards
     
    SilverStorm likes this.
  13. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    50
    If I were to write my own I could, but was looking for a way to do it within the ccp statemachine.
     
  14. Mythran

    Mythran

    Joined:
    Feb 26, 2013
    Posts:
    76
    Sorry then. Seemed a generic question.
     
  15. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    50
    All good, will see what lightbug says
     
  16. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Hi,

    Add this to the CharacterStateController.cs file:
    Code (CSharp):
    1.     public void EnqueueTransition<T>() where T : CharacterState
    2.     {
    3.         CharacterState state = GetState<T>();
    4.  
    5.         if( state == null )
    6.             return;
    7.      
    8.         transitionsQueue.Enqueue( state );
    9.     }
    10.  
    11.     // New stuff -------------------------------------------------------------
    12.     public void EnqueueTransition( CharacterState state )
    13.     {
    14.         if( state == null )
    15.             return;
    16.      
    17.         transitionsQueue.Enqueue( state );
    18.     }
    19.  
    20.     public void EnqueueTransitionToPreviousState()
    21.     {
    22.         EnqueueTransition( PreviousState );
    23.     }

    That's interesting. You can achieve this by using the PhysicsComponent API (SphereCast, CapsuleCast, Overlap, etc) from the CharacterActor. However, i think this would need to be integrated inside the actor (some sort of autoSize feature or something).

    At the moment you can access the CharacterCollisions class (responsible for physics queries ) and then call CheckBodySize:
    Code (CSharp):
    1. public bool CheckBodySize( Vector3 size , Vector3 position , HitInfoFilter hitInfoFilter )
    2. {
    3. ...
    However, this will only tell you if the character is overlapping with something or not, it wont say anything about the target height, which means that you would need to iterate over and over trying different sizes (not the best solution).
     
  17. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    676
    Hello Lightbug I have gone through quite a far with your package and now I have something to show! Attached in the zip is a video of some movement and combat with an enemy.

    I also have some questions, since you've updated your plugin and I'm using it what's the safest way to update it without breaking things. My package should be 1 month old by now.

    Lastly what is the best way to knockback my hero a little bit using the CCP say when an enemy attacks him he should get slightly pushed back? Would Rigidbody stuff like impulse work-meaning I would then need to add a rigidbody to the CCP which might break something or does the CCP have a custom integration for knockback?:

    Update: I've noticed on play a rigidbody is attached to the player magically, is this ok to call methods on like impulse?
     

    Attached Files:

    Last edited: May 24, 2021
    lightbug14 and Broudy001 like this.
  18. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Nice! glad to see the project is growing.

    The best way to evaluate this is (1) by knowing how the asset is versioned and (2) by reading the release notes.
    My way of versioning the package is based on risk.
    - "Fix/patch" updates are pretty safe, meaning that you won't experience issues.
    - "Feature" updates can introduce a few important changes, normally this involves console errors (API changes) but nothing extremely different (2 min changing stuff and you will probably be ready to go, it depends on the update).
    - "Major" updates really change the package (like a "v2" version of it).


    I don't recommend this since there are properties that are being controlled by the character actor (physics material, drag, angular drag, etc). It is true that you can change the mass, the friction, use joints, that's ok. However, there is no guarantee that everything is going to work (compared to a vanilla RB).
    Also this component is trying to predict a lot of things, so "velocity" (prior to the physics simulation) is what this controller use. Impulses and forces doesn't manifest in any way (at least Unity doesn't expose this to us), so they normally get completely ignored by the actor.
    There is a way to use similar functions, just get the RigidbodyComponent component (from CharacterActor) and call them from there. For example:
    Code (CSharp):
    1. CharacterActor.RigidbodyComponent .AddForce( ... );
    These methods translate forces into velocity (the result should be pretty much the same).
     
    SilverStorm likes this.
  19. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    676
    What do you think would be the best way to make the player get knocked back based on the enemies facing direction. So if the enemy is looking at the player the player will be knocked back backwards.

    Using that code in the fixed update is creating strange results.
    The player will not move at all if the value for example on the x is below 50.
    Making is above 50 the player moves about 2 metres away.
    When the player is in the air he moves triple the distance which doesn't seem right....
     
    Last edited: May 28, 2021
  20. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    It depends on the the knocked back (KB) effect that you want. You can produce a "natural" KB based on the current acceleration/deceleration settings (from NormalMovement). For example, if you character deceleration is too high (e.g. mud material) impulses won't last long. On the other hand, if this deceleration value is super low (e.g. ice) the KB effect will last "forever".
    This is one way to do it. You can also produce that KB manually by specifying a certain duration + initial velocity (the dash effect works in a similar way). This ignores any acceleration/deceleration settings, since you are controlling the velocity frame by frame.


    I think the stable state might be affecting your character, especially if the KB direction is not projected onto the ground plane. Stable characters don't have any vertical velocity (this stuff is handled internally by the actor). You can try to call ForceNotGrounded before applying that Force/Impulse, just to see if the results are consistent. This is why producing a jump requires a ForceNotGrounded call, all that vertical velocity will be lost if the character remains stable.
     
  21. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    676
    The kind of KB I am looking for is a very simple one where the player gets hit by an enemy and is launched back a small amount say 50cm. It should be a universal effect that doesn't take into account your speed or environment. They usually get KB based on the enemy's forward facing direction to push you away from them or it could be a random direction push away. The effect should work the same whether you are in the air or on the ground. It is a straight line knockback rather and not a launch in the air kind.

    The Dash example is a great example of the kind of knockback because it freezes the player for a bit and that's cool. So I was thinkig to have that kind of effect but keeping the player looking at the enemy as he is pushed back whether on land or air. If he is pushed back while in the air we can continue gravity or we can freeze it until the knockback finishes whatever is better.
    Lastly I recall that in the demo there are wind forces that affect the player on that spinny thing so I'll look into that too.
    While it's not mandatory most platformers have an effect which will kick the player backwards if the get hit by an enemy or come into contact with a dangerous obstacle-it's a very basic implementation but it's pretty cool.
    Since your controller interferes with the usual rigidbody and physics commands that Unity has implemented it forces me to ask you to create some clear example code if possible and post it here so that others can utilize this with the CCP.

    Is that a reasonable request?
    *The knockback should not allow the player to control the character during it's duration which is usually half a second or less.
     
    Last edited: May 29, 2021
  22. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    676
    I have another question regarding how to kill the player and also kill the CCP from processing so that player can focus on the Game Over menu or lose a life and respawn.
    This is my current code to stop the player from moving, jumping and rotating.
    This works fine but I'd like your input in cases changing these values would break anything elsewhere in the CCP.

    Does the CCP have a simple bool call or anything like that to do what I'm trying to do or will what I have do fine for killing the player and general control?

    if (Health <= 0)
    {
    Player_Audiosource.PlayOneShot(playerdeathsfx, 1);
    IsAlive = false;
    Animator_Reference.SetBool("Is Alive", false);
    CharacterStateLink.GetComponent<NormalMovement>().verticalMovementParameters.canJump = false;
    CharacterStateLink.GetComponent<NormalMovement>().planarMovementParameters.baseSpeedLimit = 0;
    CharacterStateLink.GetComponent<NormalMovement>().planarMovementParameters.canRun = false;
    CharacterStateLink.GetComponent<CharacterStateController>().ExternalReference = null;
    CameraReference.GetComponent<Camera3D>().enabled = false;
    }

    The current code will stop his speed, stop his ability run and jump and it stops his ability to rotate his body and stops the camera's ability to rotate. In theory I reverse this and everything should be up and ok (he comes back to life).

    The only issue is warnings that the character external reference cannot be empty lol.
     
    Last edited: Jun 4, 2021
  23. willrhodes

    willrhodes

    Joined:
    Mar 2, 2018
    Posts:
    3
    Has anyone run into any problems with using a Cinemachine Collider with this asset? I'm having an issue where whenever the Cinemachine Collider hits something, my character becomes ungrounded/unstable, even when just standing perfectly still. I'm just using the NormalMovement state from the Demo for now.
     
  24. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    50
    None that I've noticed so far, but I'm not using normal movement state
     
  25. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    676
    It's been a week and there's not been a response to any questions. Hope @lightbug14 is ok.

    *Note: I'm trying to make the player bounce on a trampoline and this issue also ties into the last post about knockback as that also is not working right but these are connected issues.

    I think there may be a bug with this package where collisions are not registered properly.
    It's very simple in the characters script just call the oncollisionenter or ontrigger enter which looks for a tag for the object that you collided with and have it print a debug log telling you that you collided with it like so:

    if (other.gameObject.tag == "Trampoline" && GetComponent<CharacterActor>().IsGrounded == true)
    {
    Debug.Log("We hit the collision object");
    }
    My issue is depending on the version of the CCP it will either not register the collision at all or causes issues only registering whenever it feels like or only the sides of the object I hit.

    In general I am having a lot of trouble figuring out how to detect if the CCP has landed on the surface of an object with it's feet. I have given a tag but obviously that code is detecting the sides of the CCP and not the bottom or top.
    I cannot find anything in the reference documentation regarding if the feet of the CCP has hit an collision object. Furthermore OnTriggerEnter is only working when the character jumps off the object and not onto it (Works better in newer update but only some of the time registers).

    So I'm getting really annoyed here I cannot proceed further with the CCP until these problems are addressed it's clearly a bug since the update has changed some of how it works but it's still bugged.

    Another issue Is that I'm not using the Normal Movement parameters I am using my own but I am getting constant warnings that I don't have the animation parameters It's asking for.
    I had to disable the public override void PreCharacterSimulation( float dt ) method in order to stop the errors. I don't get why it's demanding these off me since I have set the override animation controller to be false.
     
    Last edited: Jun 10, 2021
  26. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    I've been very active (the email is the official support channel). In fact, i'm replying now because you've sent me an email ;)
    I'm fine thanks.

    No error, the collider is not touching the ground (OnCollisionEnter won't be called at all). This is why you have a ground trigger option in the inspector. You can use this to trigger events from external components (e.g. jump pad from OnTriggerEnter). If you need to do the same thing from the character pov then use CharacterActor public properties.


    Here you have the API reference: https://lightbug14.github.io/lightb...troller_pro_1_1_core_1_1_character_actor.html
    And this is from the documentation:
    https://lightbug14.gitbook.io/ccp/f...or/collision-properties#collision-information

    You can use if( IsGrounded && !WasGrounded){...}, or maybe use the event OnGroundedStateEnter, or maybe asking for the GroundObject properties (transform. rigidbody, collider, etc. ). Do you need this information before or after the physics simulation?

    This public field overrides your current runtime animator controller with a new one. However, this doesn't mean your Animator should stop getting updates from the state (e.g. one big animator + multiple states updating data).
    If you don't need these parameters then ignore/remove them. You can either remove the method (like you did) or remove the parameters (fields).

    It is working for me. If you think this is not working as expected then report a bug (to my email of course, then upload it here if you want). I would need:
    - step-by-step instructions on how to reproduce the issue.
    - version of the asset.
    - relevant scene elements if needed (or maybe a unitypackage).
    - extra info (always help).

    What Physics calculations exactly? The controller is not doing physics calculations at all, it is just creating a displacement vector from an input velocity, and doing physics queries in order to predict movement (modifying an existing input velocity). Physics calculation (= defining that input velocity) is something you (the user) needs to do.
    Collision detection/response (+messages/events) is handled by Unity.

    Well, mainly because:
    1. This is not the place to report bugs. Also i didn't receive any messages related with this,so maybe this is happening only to you (due to scene settings, character properties, code, or whatever). If you want to share X bug with others then it is perfectly fine, but remember that the email goes first.
    2. Is this an issue or not? Maybe the result you are getting is expected in a way. By "expected" i don't mean it is good for your particular project.
     
    Last edited: Jun 11, 2021
    SilverStorm likes this.
  27. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    676
    No worries I will start sending emails, I will do my best to record a gameplay footage and show you my setup and code so we can track this down.
     
    lightbug14 likes this.
  28. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    That would be great, thanks.
     
  29. ml785

    ml785

    Joined:
    Dec 20, 2018
    Posts:
    50
    Hi,
    How do you think this asset would do for getting a "hookshot" ability to work?
    Like this (First 5 seconds preview it):


    Do you think a hookshot ability would work with CCP? If I bought CCP, I would have to follow a way different method to get hookshot working with CCP than than just copying a random YouTube video's Rigidbody-based code, right?

    I am just trying to gain an understanding of how the process would be to add hookshot to CCP. Thank you
     
    Last edited: Jun 13, 2021
  30. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Hi @ml785 ,
    You can add any kind of joint to the character. One thing to consider is that the character (especially a "stable" character) will still execute its internal tasks such as projecting velocity, sticking to the floor, follow a platform, maintaining the rotation, etc (see the video). For this particular case, your character will be unstable (not grounded) while using the gun, so i think it will behave just like the one in the video.

    Here is a little video i made (the values are wrong, sorry for that).

     
    ml785 likes this.
  31. ml785

    ml785

    Joined:
    Dec 20, 2018
    Posts:
    50
    Thank you! Also, do you have plans for implementing, or recommendations on how to implement, a swimming ability with CCP?
     
  32. RafaelGuimaraesBarbosa

    RafaelGuimaraesBarbosa

    Joined:
    Dec 14, 2019
    Posts:
    15



    Would you like to make a tutorial or create a demo with the new Input System?


    I followed the tutorial in the manual: https://lightbug14.gitbook.io/ccp/how-to.../implementation/use-the-new-input-system
    , but it's giving the following error:


    NullReferenceException: Object reference not set to an instance of an object
    NewInputSystemHandler.GetBool (System.String actionName) (at Assets/script/CCP/Actions/NewInputSystemHandler.cs:26)
    Lightbug.CharacterControllerPro.Implementation.CharacterActions.SetValues (Lightbug.CharacterControllerPro.Implementation.InputHandler inputHandler) (at Assets/Character Controller Pro/Implementation/Scripts/Character/Actions/CharacterActions.cs:99)
    Lightbug.CharacterControllerPro.Implementation.CharacterBrain.UpdateBrain (System.Single dt) (at Assets/Character Controller Pro/Implementation/Scripts/Character/Actions/CharacterBrain.cs:205)
    Lightbug.CharacterControllerPro.Implementation.CharacterBrain.Update () (at Assets/Character Controller Pro/Implementation/Scripts/Character/Actions/CharacterBrain.cs:179)


    I don't have good English, maybe I missed something in the tutorial, I also tried creating New Assembly getting the file com.lightbug.character-controller-pro as definition


     
  33. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Hi Rafael,
    let's go step by step:
    1. This -> https://lightbug14.gitbook.io/ccp/h...w-input-system#missing-references-asmdef-file will fix the missing reference issue. The missing reference error can be easily avoided by putting the input handler (new input system) outside CCP's main folder (not part of another asmdef file). No need to create any extra asmdef file anywhere.
    Once you have this working (no compilation errors) then ...
    2. Actions (based on their names) will be read from the input action asset (CharacterActions.inputactions in this case). These actions (by default) are Jump, Movement, Dash, JetPack, Pitch, Roll, and so on. Make sure your CharacterActions asset contains these actions.
    I can confirm that those actions are there (i tested this yesterday), unless you have a very old copy of that same asset file (1 year ago or so). If so, then download the asset file from the documentation page (that same link).

    If you modify the actions (e.g. by creating your own actions), then you need to update the asset (CharacterActions.inputactions) as well.


    What kind of swimming ability are you looking for?
    In the past i made a swimming ability for a client (wow style) and it worked pretty well. The tricky part is always getting out of the water. In that particular state that i made i decided to use the LedgeHanging state just for this (this is why you can find a "force auto climb up states" list in the inspector).

    The basics are (during the Swimming state):
    - keep the character upwards (if you want to, i did this in the past and it worked).
    - make sure your character is "alwaysNotGrounded".
    - modify the "graphics" object in order to tilt the body towards velocity (this is something i will add in the future) ... or use animations (i chose this, it was a lot of work).

    I would recommend to use ZeroGravity movement code (or even the entire state) as your starting point (ignore Roll and Pitch if you want).
     
    Last edited: Jun 29, 2021
    ml785 likes this.
  34. RafaelGuimaraesBarbosa

    RafaelGuimaraesBarbosa

    Joined:
    Dec 14, 2019
    Posts:
    15
    Discovering the error, I had created a state called Fire Bomb, it hadn't registered in CharacterActions.inputsactions.
    Thank you for your help
     
    lightbug14 likes this.
  35. Last_Imba

    Last_Imba

    Joined:
    Feb 25, 2017
    Posts:
    35
    Hi, @lightbug14
    Could you tell me please, how to fix not smooth rotation of the "gun" in first person mode? As I understand, this rotation bug appears due to the interpolated FixedUpdate nature.
    Here is a video, I hope it helps to understand what I am talking about.

     
    Last edited: Jul 1, 2021
  36. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Hi,
    I don't really know how are you handling this, is the gun an independent object or not (child)?. Also, I'm not sure which target are you using for the gun (if there is a script or not), i'm going to assume your target is the "character/graphics" object, and not the camera (based on that video).

    That being said, i think this is happening because:
    1. The gun is not following a Transform target. If you're using the Rigidbody as the reference, you'll similar results (or even worse).
    2. The gun is following a Transform using Update, but it is behind it all the time (1 frame of delay). This can be happening because the execution order is wrong (e.g. you are updating the gun before the character interpolates the body).
    3. The gun is being updated (e.g. lerp) in FixedUpdate instead of Update/LateUpdate.


    You can fix this by either:
    A) Making the gun a child of the character (like i did with the arrow on top of the capsule head). Interpolation will take care of the gun. The obvious problem (or not, it depends) is that the gun won't be 100% "free" (if the character rotates then the gun will do the same) ... or
    B) Using the character/graphics transform as the reference for your gun + using Update/LateUpdate.

    This video shows the gun as a child of the "character" (first part) and the "graphics" object (second part).


    Note how rotation is not really affected whatsoever, this is because it is handled by the interpolation + looking direction logic (NormalMovement). However, vertical displacement is awful when the target = character, simply because the camera is following the "graphics" (as it should) whereas the gun is following the root object (two different things).
     
  37. CoastKid

    CoastKid

    Joined:
    Jan 8, 2013
    Posts:
    38
    Hi, @lightbug14
    I bought Character Controller Pro few days ago, and I was very impressed! It is a very great asset!

    However, I ran into a problem using Edge Compensation in combination with Vertical Displacement Interpolation of the Graphics component.
    Stepping up and down is never smooth when Edge Compensation "on" for some reason, no matter what Positive and Negative Displacement Speed values are.
    Is there a way to make this "combo" works smooth somehow?
     
    lightbug14 likes this.
  38. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Hi, thank you very much!

    You are correct. The reason why this looks bad is because a cylinder shape transitions from height A to height B in a single frame. The capsule (no "edge compensation") is accumulating all those small displacement values over time, producing a smooth transition.
    This issue is tied to the method i'm using to produce those results. The algorithm responsible for that takes the ground probing displacement (CharacterActor -> ProbeGround method) and accumulates that over time using a buffer.
    Code (CSharp):
    1. currentVerticalDisplacement += groundProbingDisplacement / 5f;
    That "5" is there to prevent overshoot.

    Then, the component tries to reduce this amount using a lerp function (from current value to zero).
    Code (CSharp):
    1. currentVerticalDisplacement = Mathf.Lerp( currentVerticalDisplacement , 0f , t );
    The problem with the cylinder-shape is that this accumulated value grows very quickly (especially if you use big stairs).
    One thing you can do is to replace that "5" with "10".
    I'll try to find a better way to handle this.

    Thanks for reporting this.
     
    CoastKid likes this.
  39. Wilomomo

    Wilomomo

    Joined:
    Jul 6, 2017
    Posts:
    4
    @lightbug14
    Hi =)
    Can we force an actor to be not stable ? I want to make my CC unstable on some layers, but I don't know how to ^^
    I've read the docs but can find what I search for and isStable property is read only ^^
    Thank you =)
     
  40. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Hi,
    Unfortunately this is not possible in 1.3.5 :( The good news is that i've implemented 5 minutes ago. It will be available in 1.3.6 (which is almost ready).

    Forcing IsStable to false might break the actor behaviour (for example, the "prevent bad step" functionality). So, i ended up adding a new layer mask which contains all the potential stable surfaces (by default this is "Everything"). If you need to create "unstable layers" then you need to remove them from this layer mask.

    Thank you for mentioning this feature, it seems quite useful.
     
  41. Wilomomo

    Wilomomo

    Joined:
    Jul 6, 2017
    Posts:
    4
    Thank you for you answer =)
    Do you know when your update will be available ?

    Thank you ! =)
     
  42. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Wednesday
     
  43. yunum844

    yunum844

    Joined:
    Jul 6, 2021
    Posts:
    27
    Last edited: Jul 21, 2021
  44. Gamingbir

    Gamingbir

    Joined:
    Apr 1, 2014
    Posts:
    182
    Hi, I am interested to buy the asset but it works on 3D meshes with 2D physics? Also, what is the best way to reach you? Email or this forum thread? I am making a 2.5D Metroidvania similar to



     
  45. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Hi, 1.3.6 has been uploaded (pending review).

    Sorry for the delay, improving the root graphics interpolation was tricky as hell :(. I'll write the release notes as soon as possible.

    Hi, thanks for the interest in the asset!

    The controller works with 2D and 3D physics. The 3D mesh that you see (2D demo) is there because i'm lazy and didn't want to create a 2D sprite-based character with animations :)

    Bloodstained uses (i think) 3D physics. Choose 3D Physics over 2D Physics if you can, 3D is faster (yeah), it looks fantastic (collision detection) and has more features than 2D.

    The Email is the official support channel.
     
  46. Bluelight413

    Bluelight413

    Joined:
    Feb 8, 2018
    Posts:
    4
    I'm trying to add some additional functionality to the character used in the 3d Scene. I want to make it so that when a dash is performed in the air, it sets the NormalMovement's notGroundedJumpsLeft value to 1. This would allow the player to perform a second midair jump after a dash, kind of like how A Hat in Time does it.

    Right now I'm trying to do this by modifying the Dash state's script to reset NormalMovement's notGroundedJumpsLeft value during the EnterBehaviour function. I can't figure out how to modify a variable from another state. Below are a couple of ways I've tried referencing it.

    What's the proper way to reference and modify another state's variables? And, is there a better way to achieve the result I'm aiming for?
    upload_2021-7-23_16-49-20.png upload_2021-7-23_16-55-27.png
     

    Attached Files:

  47. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Hi,
    A state is just a MonoBehaviour component, so if you need to use an external reference (to another state for example) then you need to get that component first (Awake, Start, etc...).
    The state machine contains all the available states (from the character) inside a dictionary. This is why you can use the GetState method (similar to GetComponent<T> ):
    Code (CSharp):
    1. *State name* someState = CharacterStateController.GetState<*State name*>()
    Regarding those errors:
    1. The first error (1st image) is there because that variable is not static (=> you cannot use "ClassName.someVariable").
    2. The second error is there because you can't use GetComponent and pass a float variable as a type (it needs to be a "Component" type).

    You can achieve this "A Hat In Time" effect by using the OnEnterBehaviour method from NormalMovement. If the "fromState" is "Dash", then reset the not grounded jumps to the default value:
    Code (CSharp):
    1. public override void EnterBehaviour( float dt , CharacterState fromState )
    2. {      
    3.         //...      
    4.         //...
    5.    
    6.         if( fromState == CharacterStateController.GetState<Dash>() )
    7.                notGroundedJumpsLeft = verticalMovementParameters.availableNotGroundedJumps;
    8.    
    9. }
    See if this works.

    IMPORTANT: Remember that these are demo states, if you want to tweak them then put them outside the asset folder (otherwise your progress will be lost when you update the asset).
     
    Bluelight413 likes this.
  48. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    163
    Is it possible to use Burst/JobSystem to optimize the sim overall performance ?
     
  49. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    Maybe, it depends on how much work can be jobified. The main issue that i see is that actors execute specific functionalities from the main thread (Physics and Physics2D) such as CapsuleCastNonAlloc and SphereCastNonAlloc. I know about CapsuleCastCommand and SphereCastCommand (compatible with jobs), however, those alternatives (i think) won't work because they are not "All" versions (which is required if you are detecting obstacles). The RaycastCommand struct IS a valid alternative for RaycastNonAlloc.
    Also, jobs-compatible 2D Physics queries are not supported yet ... and probably never will (https://forum.unity.com/threads/raycastcommand-usable-with-raycasthit2d.530232/).

    This doesn't mean the Job system cannot be used. The right thing to do first is to identify the bottleneck area, and then jobify the code.
     
  50. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    348
    After some "refactoring" i was able to get more performance :)

    Performance scene (IL2CPP):

    Before: 500-550 3D characters
    Now: 650-700 3D characters

    (I'm using a Ryzen 5 3600)
     
    filod likes this.
unityunity