Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Released] Kinematic Character Controller

Discussion in 'Assets and Asset Store' started by PhilSA, Sep 29, 2017.

  1. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Thanks for replying.

    The problem is velocity should sync with animation. So if velocity is changed quickly the animation will not smooth.
    Because of that I have an idea and it will be great which I know your opinion about my idea.

    I want to make velocity zero immediately after these situations:
    1. Player doesn't hold movement keys anymore.
    2. Change direction (In all of those 8 directions)
    3. Quick changing in camera look

    And there is a seperate animation in these situations.

    But I don't know how to determine direction change and quick turns (Camera look changing) yet. Do you have any idea ?
     
  2. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    Eh, if your animations aren't responding to quick velocity changes, it sounds more like an issue with them than the controller. Reactive animations with a low input-to-motion latency make for more responsive gameplay.

    But, if you absolutely must have animations affect velocity, you can use Vector2.Angle or Vector2.Dot to compare the previous and current movement input (and their Vector3 equivalents, for camera direction). Then, you can set a bool or state enum value that you can check later to ignore input temporarily. As for clearing velocity, I generally set a _currentVelocityClearRequested bool when needed and consume that on the next velocity update (clearing the current velocity and setting the bool to false).
     
    Alvarezmd90 likes this.
  3. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    @OhiraKyou It responses but it's not smooth. I have sprint state for my player. so from walk to sprint I should have smooth animation.
    There is a variable which is called speed in the character animator and this variable controls blending between walk and sprint animation. This variable depends on BaseVelocity by an equation.

    ((_motor.BaseVelocity.magnitude - _stats.maxWalkSpeed) / (_stats.maxSprintSpeed - _stats.maxWalkSpeed))


    So I don't think so the problem is in animation part but maybe is. Do you think it is ok ?

    upload_2018-12-19_11-13-29.png
     
  4. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    I like to think of player character animations as confirmations and manifestations of the player's intent. As such, I generally prefer to use movement input to drive animations rather than velocity. This makes characters feel more responsive.

    For example, while running into a wall, I prefer to continue playing a running animation (due to input) than no animation (due to zero velocity), because I consider showing the player that their intent is being registered more important than showing them that they are not moving. The player can already tell that they are not moving without an animation telling them so, and players will generally not walk into a wall for no reason. So, even if it looks silly when it happens, it won't matter, because, in practice, no one will intentionally walk into a wall. And, if they do, it should be clear that their input is still being registered so that they don't think they're stuck and unable to move.

    In my case, I use movement input magnitude both to drive changes in animation state (walking/running) and as a multiplier for animation speed.
     
    andreiagmu and Alvarezmd90 like this.
  5. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Hmm, I'm not sure if it is good enough for syncing animation and movement.
     
  6. bentontr

    bentontr

    Joined:
    Jun 9, 2017
    Posts:
    39
    Ran into a very minor issue in KinematicCharacterMotor.cs. If you parent and un-parent your character motor, you may find that the lossyScale warning may be logged in the editor, even if the scale is correct. This is because the epsilon used for Approximately is quite small and when an object is re-parented the scale may change to something like 1.0001, which actually fails the check. Instead, simply compare the vectors directly since it has a larger epsilon:

    if (Transform.lossyScale != Vector3.one)
     
    f0ff886f likes this.
  7. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    118
    I'm attempting to get a first person controller working on a rotating planet much like in the demo scene. However, since it's a first person controller, the character's rotation is set to face the camera's orientation, naturally. This is causing the character to ignore the rotation that should be applied to it from standing on the planet (the ground seems to rotate underneath the character even when the character is standing still.)

    Would this be fixed by handling the simulation in the KinematicCharacterSystem script manually so that the rotation that should be applied to the character caused by the planet is added to the character's rotation, or is there a simpler way?
     
    Alvarezmd90 likes this.
  8. Alvarezmd90

    Alvarezmd90

    Joined:
    Jul 21, 2016
    Posts:
    151
    I really hope Phil will become more active next year.
     
    a-t-hellboy likes this.
  9. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    223
    RogDolos likes this.
  10. Shturmovik

    Shturmovik

    Joined:
    Nov 5, 2014
    Posts:
    29
    Looks like that new official controller has some real potential, but is not *quite* ready for prime time yet - and considering Unity's history of delays and orphaned systems, I'll stay with KCC for now - even if it should never receive another update. I've built a solid code base around it by now that integrates well with the other 3rd party systems I'm typically using, so will go forward with that in my new project.

    While it would still be great to see KCC updated, it's already a rock solid and well focused system, so I have absolutely no qualms sticking with it for the foreseeable future.
     
  11. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Hey there,

    I want to change jump code in example a little bit.
    I want to have movement in air but by one constraint, by holding movement keys in any direction, character can't travel more distance than constant jump distance. (I don't really know if I explain it clearly :D). Like jump in Fortnite.

    Do you guys have any idea how to achieve it ?

    Edit: It is solved
     
    Last edited: Dec 30, 2018
    Alvarezmd90 likes this.
  12. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    223
    Agreed, after sometime play with it, it prove itself very WIP. (check my post), but it did provide some ideas about how to achive animation & movement effects stuff (actually , i think it may even be possible to replace OpenCharacterController with KCC :D)

    It'll be great if you can share more about your experiences in using KCC.
     
  13. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Guys what is the difference between FoundAnyGround and IsStableOnGround ?
     
  14. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Guys I want to determine my next state when character land after jumping. My problem is the BaseVelocity is not correct value and according to that I determine if it is walk state or sprint state. Do you guys have any idea ?
     
  15. Shturmovik

    Shturmovik

    Joined:
    Nov 5, 2014
    Posts:
    29
    Great work on finding problems with the new standard controller. That obstacle ground from KCC might well become the new international standard for testing character controllers! :D

    Regarding my experiences with KCC, I've basically just trawled through this forum for ideas, and also expanded on some of the stuff in the KCC walkthrough.

    I'm currently working on level design tools for my project, but I'll be happy to share what I'm doing with KCC when I return to working on that. One of the things that might be of general interest is integration with the add-on packs for Opsive's Behavior Designer, but I'm not allowed to share that in public as it's based on Opsive's code - but I might contact them and see if it can be made available as a download for registered users on their official site.
     
    filod likes this.
  16. iamtommo

    iamtommo

    Joined:
    Aug 25, 2017
    Posts:
    3
    Any chance you'll be ECS/Job-ifying this? I'd be fine with it being a brand new asset on its own.
     
  17. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    223
    I managed to make SAC 's ThirdPersonController work with KCC (to replace OpenCharacterController), things are going well:
    upload_2019-1-3_14-25-56.png
    preview here


    but still many bugs in ThirdPersonController, the way ThirdPersonController handles movement is quite complex, i'd prefer match movement rather than compute RootMotion to drive OCC/KCC
     
    Last edited: Jan 3, 2019
    Alvarezmd90 and Vincent454 like this.
  18. Alvarezmd90

    Alvarezmd90

    Joined:
    Jul 21, 2016
    Posts:
    151
    Very nice. I like the roll animation upon landing.
     
  19. Derlix

    Derlix

    Joined:
    Jan 6, 2019
    Posts:
    4
    Hi. I have a little problem with the "Max Distance from Ledge" . My Character has a very small feet base (but still a wide body), so i reduced this value. Now he isn't stable when there is no ground the feet base could stand on, but i expected the character to slide of the edge in this case. He does...but veeeeeeeeeery slowly. Like the capsule has a sticky material while sliding of. I tried to use a slippy physics material in the physics material slot of the motor, but this doesn't help.

    Can you help me with this problem?
     
  20. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    I mentioned the slow falling from edges on the previous page. Not sure how to fix it yet. I've tried implementing my own solution by forcing a fall when on the outside of a ledge, but that resulted in some very weird grinding-like behavior when falling from an edge while walking along it.

    Another unsolved issue is that there seems to be some normal averaging/smoothing going on that makes it possible to walk up an edge between two otherwise unwalkable slopes. Two wrongs do actually make a right, apparently. Here's an example with the max stable slope set to 46:
     
  21. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    I only trust currentVelocity, at the start of the UpdateVelocity function, to be accurately representative of the controller's effective velocity, as this value reflects automatic processing done by the motor.

    At the end of the UpdateVelocity function, I save currentVelocity's final intended value to a variable that I reference to trigger and modify effects. For example, on landing, I check this saved velocity value to determine the volume of my character's on landing thump sound.
     
    a-t-hellboy likes this.
  22. Youdaman

    Youdaman

    Joined:
    Apr 8, 2017
    Posts:
    8
    I've managed to get the Kinematic Character Controller asset working with Forge Networking Remastered but I need to now make it server-authoritative and would like some hints and tips please -- I'm guessing it's a matter of shuffling some logic around and using conditions like `if (!networkObject.IsServer)` etc

    fyi the `controller.velocity` is used to update the velocity as per KCC's prescribed method:

    public override void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime) => currentVelocity = velocity;


    Code (CSharp):
    1. using BeardedManStudios.Forge.Networking.Generated;
    2. using KinematicCharacterController;
    3. using UnityEngine;
    4.  
    5. public class PlayerCapsule : PlayerCapsuleBehavior
    6. {
    7.   public float speed = 10f;
    8.   public KinematicCharacterMotor motor;
    9.   public PlayerCapsuleController controller;
    10.   public KinematicCharacterMotorState state;
    11.  
    12.   private Color color;
    13.  
    14.   public Color Color
    15.   {
    16.     get => color;
    17.     set => GetComponentInChildren<Renderer>().material.color = color = value;
    18.   }
    19.  
    20.   protected override void NetworkStart()
    21.   {
    22.     base.NetworkStart();
    23.     networkObject.UpdateInterval = 7; // ~ 1000ms / 128 tick
    24.   }
    25.  
    26.   private void Awake()
    27.   {
    28.     Color = PickRandomColor();
    29.     KinematicCharacterSystem.AutoSimulation = false;
    30.     controller = GetComponent<PlayerCapsuleController>();
    31.     state = new KinematicCharacterMotorState();
    32.     state.Rotation = Quaternion.identity;
    33.   }
    34.  
    35.   private void Update()
    36.   {
    37.     if (networkObject != null && !networkObject.IsOwner)
    38.     {
    39.       Color = networkObject.color;
    40.       state.Position = networkObject.position;
    41.       Tick();
    42.       return;
    43.     }
    44.  
    45.     if (Input.GetMouseButtonDown(0))
    46.       Color = PickRandomColor();
    47.  
    48.     controller.velocity = new Vector3(
    49.       Input.GetAxis("Horizontal"),
    50.       0,
    51.       Input.GetAxis("Vertical")
    52.     ) * speed;
    53.  
    54.     Tick();
    55.  
    56.     if (networkObject != null)
    57.     {
    58.       networkObject.color = Color;
    59.       networkObject.position = state.Position;
    60.     }
    61.   }
    62.  
    63.   Color PickRandomColor()
    64.   {
    65.     return Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
    66.   }
    67.  
    68.   void Tick()
    69.   {
    70.     motor.ApplyState(state);
    71.     KinematicCharacterSystem.Simulate(Time.deltaTime);
    72.     state = motor.GetState();
    73.   }
    74. }
     
  23. FoodFish_

    FoodFish_

    Joined:
    May 3, 2018
    Posts:
    58
    Any developments on this issue? I facing the same difficulty...
     
  24. FoodFish_

    FoodFish_

    Joined:
    May 3, 2018
    Posts:
    58
    Hello, how would you handle pushing other characters (I.e bumping other Character Controllers, lets say an Npc).I understand interaction with non-kinematic bodies is provided but I am struggling to interaction between 2 character controllers. Thanks for the help
     
  25. Niels40

    Niels40

    Joined:
    Nov 6, 2017
    Posts:
    20
    I have been at the kinematic controller asset and have a couple of questions.

    In my case specifically i need a character controller that can move on a moving ship. I however do not want the character to slide away if the deck is slightly rotated.

    The game itself is in first person.
    Do you think i can achieve this with kinematic character?

    And a more important question. Would i need to use the BaseMoveController or can i keep my current movement of the boat
     
    Last edited: Jan 16, 2019
  26. wgj0522

    wgj0522

    Joined:
    Oct 19, 2015
    Posts:
    4
    one bug in version 2.3.0.
    the Climbing Ladders sample scene,pressed "E",it will enter ladder,but exit ladder immediately.so i modify the code.
    OnStateEnter()
    case Climbing:
    Motor.SetGroundSolvingActivation(false);
    OnSeateExit()
    case Climbing:
    Motor.SetGroundSolvingActivation(true); //recover detecting the ground.
    Is this OK?
     
    Vincent454, Alvarezmd90 and OhiraKyou like this.
  27. deiterate

    deiterate

    Joined:
    Jul 10, 2015
    Posts:
    9
    Nice find! This actually does appear to solve the problem with the Ladder Climbing walk-through example. A character generally does not need ground solving while on the ladder and its using the ladder segments to determine transitioning off the ladder, so ground solving isn't required to detect the bottom of the ladder.

    I guess that is probably why adjusting the bottom segment length to can work too. Prior to testing your suggestion, I managed to get the example working by adjusting the bottom segment of each ladder to be larger. I suspect that allowed it to bypass ground solving.

    Although I could be wrong, this seems like the correct solution for getting climbing ladders working, at least for that walk-through example.
     
  28. Alvarezmd90

    Alvarezmd90

    Joined:
    Jul 21, 2016
    Posts:
    151
    It actually solved my problem. Couldn't make it work otherwise. I really hope we'll be seeing more features such as vine climbing, hookshot and slippery surfaces. While I am somewhat capable of programming, I'm not good in mechanics.
     
  29. igoraleftinovich

    igoraleftinovich

    Joined:
    Feb 11, 2017
    Posts:
    17
    Hi! Use this character controller and it is amazing! I use AttachedRigidbodyOverride to use dynamic platform functionality but if I use oscillation in the ExampleMovingPlatform script it has this issue like on the picture. I think the problem is that algorithm uses character transform (green circle) as pivot point but in my case it should be the point on the platform at which the character has attached to (red arrow). Could you please add this functionality or give me some advice on how to do that?
    upload_2019-1-27_21-18-53.png
     

    Attached Files:

  30. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    Hey folks. I've been eyeing up this plugin for a while. It looks awesome. But I have a couple of reservations...

    1. Does it support multiple characters? i.e. could I have NPCs controlled by this? Could I have multiplayer options with all players using their own controller? Do they all collide nicely?

    2. Is it still a viable option for Unity 2018.3 given that there hasn't been an update in a while and several reviews cite compilation errors? Is it easy to get up and running?

    3. Will it become redundant once Unity's own solution is finished? (I suspect not as they seem to put a heavier emphasis on animation which I think I'd prefer to manage myself)

    Thanks in advance!
     
    Kirbyrawr likes this.
  31. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    118
    1. Yes - looking at the detailed documentation will give you a very good idea of what that work will entail.
    2. Yes. Errors are trivial to resolve in 2018.3 unless you don't code, in which case this package is not for you.
    3. No - As of right now Unity's new CC does not perform as well as this one with regards to collision/jitter/irregular terrain. Someone posted some nice gifs of comparison tests between the two in this thread. I read a statement in that same thread that said something to the effect that the new standard assets controller is focused primarily on quick prototyping, which makes sense and is a nice resource to have.
     
  32. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    Thanks for the reply. Sounds good!

    I guess I should clarify my question #3... I know that Unity's solution is not as good right now, but I'm also aware that it's still in development. I don't need to purchase this plugin right away, so I guess I'm curious what the future holds for them both.

    It's good to know that it's geared towards prototyping only. KCC seems like it's more of a robust foundation for a complete game. I'm also a little wary of Unity add-ons in general... There's a pattern of doing the bare minimum to then ceasing further updates and improvements :/

    Anyway, I think I will make the purchase as and when I need it. It's on my Wishlist for now. :) Thanks for the help!
     
  33. RiseBasti

    RiseBasti

    Joined:
    Nov 4, 2018
    Posts:
    33
    Hello everybody!

    I've some questions about the fancy controller. I really want to buy it if I can use it for my needings.

    1. Is it possible to use it to climb on walls and ceilings? I think I'll have to code it by my one but I want to know if there would be the possibility to do so or if the controller wouldn't work correctly. (Maybe I could change the gravity to the opposite of the ground normal and rotate the characte?)

    2. If i have a player like a Tiger or something like that, would it be possible to rotate the collider to fit the 3D model or is there any other solution?
     
  34. Vincent454

    Vincent454

    Joined:
    Oct 26, 2014
    Posts:
    165
    1. should be possible, but you cannot change the collider or its rotation, it has to be a capsule collider
     
  35. RiseBasti

    RiseBasti

    Joined:
    Nov 4, 2018
    Posts:
    33
    Thank you for the information. :)
     
  36. RiseBasti

    RiseBasti

    Joined:
    Nov 4, 2018
    Posts:
    33
    I'm going to buy the asset soon but i need to know if I need to buy the asset twice if I develop a game with my friend or if we can use it together. I do not know where to find the license terms.
     
  37. chrian

    chrian

    Joined:
    May 10, 2014
    Posts:
    1
    Hey guys. I am having a problem where my character is getting stuck on staircases. I found a youtube video of someone else having the same exact problem as me. So here is the problem I am having.



    The problem happens at 0:11 in the video.

    He gets stuck on staircases sometimes, and I can't figure out why. The only thing I figured out is that this problem is more likely to occur if you set the capsule's radius to too small in the motor settings. I need my capsules radius to be the way it is right now though to fit my character so I can't just simply increase the radius to fix the problem.

    Any help would be appreciated
     
  38. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    The safe movement setting can be a bit sticky. So, if that's enabled, maybe try without it.
     
  39. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Is the controller supposed to automatically handle gravity? I got the impression it did from the feature list, but my character is not being dropped down to the surface.
     
  40. b2hinkle

    b2hinkle

    Joined:
    Apr 9, 2018
    Posts:
    2
    No. You have to implement gravity on your own.

    Also guys I made a discord server for the community using this asset. I thought it would be helpful to have one because people could get answers right away and we could also chat too about general things.

    Here is the invite link
    https://discord.gg/gk4eYkh

    Also I am hoping PhilSA sees this discord link so that I could make him the owner of the server.
     
  41. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Hey guys,

    Anyone here has used UNet or any other similar networking framework and API in KCC ? I need a sample.
     
  42. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @a-t-hellboy KCC includes a networking example that specifically uses UNET
     
  43. joaobsneto

    joaobsneto

    Joined:
    Dec 10, 2009
    Posts:
    152
    How can I make a surface that the characters slips? Or make a collider that's not detected as ground, but the characters does not pass through it?
     
  44. joaobsneto

    joaobsneto

    Joined:
    Dec 10, 2009
    Posts:
    152
    I found the solution. It's just to change the max slope. Sorry for bothering you.
     
  45. joaobsneto

    joaobsneto

    Joined:
    Dec 10, 2009
    Posts:
    152
    Actually the problem wasn't solved. I want to some places in the game that collides with the characters, but the character can't jump over it. The slope works fine, but then you jump near the edge of the collider, the controller identifies that is in a Stable Ground.
    https://www.dropbox.com/s/w8t5ecc4jn2kg3i/Captura de tela 2019-02-24 15.57.52.png?dl=0

    Even if I use tag or layer to ignore that collider from setting my character to ground state, the collision sits right on top and the gravity can take the character from this position:

    https://www.dropbox.com/s/h2yfiqwjlokubon/Captura de tela 2019-02-24 16.05.38.png?dl=0
     
  46. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    118
    Has anyone attempted to calculate the distance deltas a character has moved internally using info from the motor? I need to know how far the character has moved each frame, but my characters are able to run around on all kinds of surfaces (different gravity fields etc.) so calculating it otherwise would be more complicated.
     
  47. deiterate

    deiterate

    Joined:
    Jul 10, 2015
    Posts:
    9
    The two fields on the motor you want to track changes to create your delta's are the base velocity or velocity fields.
    I use the character motor's base velocity every frame to update my animations with a surveyor wheel style animation sequence that checks how far in the forward direction the character has moved that frame. You could store the previous base velocity and check how much it has changed to get the delta per frame. I use base velocity because I only need information about the distance the character has moved relative to any object it might be attached to. If you want to know the full total the motor has moved, you can use the motor's velocity field, which is the combined velocity of the base and any movement applied by other rigidbodies, movers, or other additive velocities that might be applied to the character.
     
    owen_proto likes this.
  48. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    118
    @deiterate I’m actually attempting to create exactly that! Thanks for the help! I was beginning to collect all kinds of info about calculating distances along the surfaces of all kinds of shapes. This will be much easier haha!

    Sounds like maybe you’ve made an implementation of David Rosen’s animation method from Overgrowth? If so, are there any resources other than the GDC talk you found particularly helpful? I think I’ve found everything I need to get it working without creating too much custom stuff, but I haven’t actually done it yet.
     
  49. deiterate

    deiterate

    Joined:
    Jul 10, 2015
    Posts:
    9
    Basically, all I do is cumulatively add up the distance traveled per frame, divide it by two times the character's scaled stride (which I change depending on 'speed' mode of the character, for instance sprinting or walking)... And then take the sine and cosine of that cumulative distance to plot the legs passing pose versus legs at full stride pose on a unit circle.

    Code (CSharp):
    1.  
    2. forwardVelocity = Vector3.Dot(Motor.BaseVelocity, Motor.CharacterForward);
    3. gaitDistance += (forwardVelocity * Time.deltaTime) / (2f * scaledStride);
    4. gaitPass = Mathf.Cos(gaitDistance);
    5. gaitStride = Mathf.Sin(gaitDistance);
    6.  
    It allows me to set up the blend tree like so

    So the actual surveyor wheel is a node in the blend tree for locomotion on my characters. If the gaitDistance is accumulating positively, the gait and stride positions move clockwise around the unit circle and blends the animations poses to appear to be moving forward. And negative accumulation makes the stride and pass rotate counterclockwise and the poses blend to appear to be moving in reverse.
     
    owen_proto likes this.
  50. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    118