Search Unity

[Released] Kinematic Character Controller

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

  1. Bubsavvy

    Bubsavvy

    Joined:
    Sep 18, 2017
    Posts:
    48
    @PhilSA
    @PhilSA I found the issue. It had to do with characterjoints we had set up for a ragdoll system for the character was causing issues. @katumplet you may want to look and see if you have any joints may it be fixed or character because they may be interfering with the way the motor is supposed to work.
     
  2. EliotVR

    EliotVR

    Joined:
    Jan 12, 2017
    Posts:
    14
    Hello. I'm developing a fps game using kinematic character controller.
    I have a question.
    How can I ignore collision with specific layers?
    Is there any example or document?
    Thank you.
     
    angelonit likes this.
  3. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Take a look at the collision-matrix.
    You can turn on/off every combination of layers in it.
    https://docs.unity3d.com/Manual/LayerBasedCollision.html
     
  4. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Yeah it does come with full source code, no hidden parts of pre-compiled dlls.
     
  5. Ellernate

    Ellernate

    Joined:
    Aug 25, 2017
    Posts:
    81
    Hey, I've ran into an odd bug that breaks the entire physics simulation, it can be reproduced easily in the playground scene with unmodified scripts. If you walk up a slope and above you there's a collider, upon intersecting the above collider the controller breaks, throwing error: "rigidbody.position assign attempt for 'Character' is not valid. Input position is { Infinity, NaN, -Infinity }." and subsequently spamming all kinds of physics errors. At this point the entire game is broken.

    Unity version: 2018.2.4f1. It can only be reproduced when "Interactive Rigidbody Handling" is enabled, and "Safe Movement" is disabled, like so: https://i.gyazo.com/9a422b054324f6f975ef91e3139570c1.png.

    Demonstration done in vanilla Playground example scene:
    https://i.gyazo.com/e458ab487337dec3df3dc82d54bfc9a9.mp4
     
    Last edited: Aug 20, 2018
  6. Shturmovik

    Shturmovik

    Joined:
    Nov 5, 2014
    Posts:
    29
    Not exactly sure what's going on with Unity at the moment, but I've run into some weird anomalies after switching to 2018.2.4f1, though mainly with my own raycast-based melee weapon system.

    Assets -> Reimport All seems to have fixed it, but the whole thing feels a bit dodgy right now ...
     
  7. ChainsawFilms

    ChainsawFilms

    Joined:
    May 28, 2016
    Posts:
    18
    I'm struggling with what may be a basic mathematical issue for some :)

    I am trying to Lean my character left or right, relative to the input axis, character direction and camera.

    The code I have works fine on with the gravity downwards, but falls apart when on a sphere planet and you can run around a changing gravity direction.

    Code (CSharp):
    1.            
    2.            // This is the section for Leaning
    3.             Vector3 CameraDirection = CharacterCamera.gameObject.transform.forward;
    4.             CameraDirection.y = 0.0f; // kill Y
    5.             Quaternion referentialShift = Quaternion.FromToRotation(Vector3.forward, Vector3.Normalize(CameraDirection));
    6.             // Convert joystick input in Worldspace coordinates
    7.             Vector3 moveDirection = referentialShift * player.axisDirection;
    8.             Vector3 axisSign = Vector3.Cross(moveDirection, Motor.CharacterForward);
    9.             Lean = Vector3.Angle(Motor.CharacterForward, moveDirection) * (axisSign.y >= 0 ? -1f : 1f);
    10.  
    Can anyone help? Thank you.
     
  8. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    224
    Any thoughts on how unity's Kinematica compare to this assets? it seems amazing in character animation, don't know whether its design goal will conflict with KCC...hmmm...
     
  9. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    135
    Nope looks like we are on our own. Biggest issue with the asset store but what ya gonna do.
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Try email support address.
     
  11. Guacamolay

    Guacamolay

    Joined:
    Jun 24, 2013
    Posts:
    63
    I really hope he hasn't left the project, it's easily the best character controller system I've used
     
  12. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    I'm attempting to convert this Character Controller into a controller that is for 2D games and 2D colliders. Has anyone else attempted this?
     
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You can use 3D colliders and it will be fine. If you are too far along then it will be a nightmare to port. This asset capsule casts multiple times to predict where the capsule will end up and I strongly suspect it's one of those cases where the behaviour will be a little different to Box2D.

    Having said that if you are not far along, it's pretty trivial to convert 2D colliders in the level to 3D ones with a script, I guess!
     
  14. Guacamolay

    Guacamolay

    Joined:
    Jun 24, 2013
    Posts:
    63
    You can also use the Planar Constraint option in the Kinematic Character Motor script to lock the controller to one axis! Perfect for 2D games
     
  15. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @hippocoder Thats a good point, I might just head that direction then.
    @Guacamolay Thanks for pointing me in the right direction! :D
     
  16. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    I'm having an issue where my player is shooting off in the positive X axis. I'm in a blank scene with only my character controller object and a simple cube for terrain. I logged my character controller velocity and it's correct in that it's only falling on the Y Axis but X axis' value remains 0, so I'm confused as to how / why my character is shooting off into + X axis. (supposedly UpdateVelocity is the only method that can move the character?)

    Any ideas what I might be doing wrong?
     
  17. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    @rxmarccall Your character is probably colliding with itself. Try putting it on a different layer.
     
    rxmarccall likes this.
  18. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
  19. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    I'm using TNet to network my game and I'm wanting to use the Core Ticking / Simulation system in KCC without any of the example networking code.

    I'm having a hard time understanding what I need to do as it feels like the core ticking system in KCC is tied to specific network functionality. For example I believe I want to use the KinematicCharacterSubsystem for manually ticking my character controllers, but then there is the SimulationSystem (required?) that appears to be tied to OnlineSession.cs which is a wrapper for UNet.

    Can someone help me understand how I can separate my KCC and the ticking system from the UNet networking implementation found in the project examples?
     
  20. Sterner

    Sterner

    Joined:
    Nov 11, 2012
    Posts:
    33
    Hi

    Does latest version support 5.6?
     
    Last edited: Sep 4, 2018
  21. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @Sterner
    I tested bringing it into Unity 5.6.3p3 and it has errors right off the bat regarding UnityEngine not having the namespace 'Playables'. Not sure if this is something you could adjust to make it work or not, but there you go.
     
  22. peanutgallery

    peanutgallery

    Joined:
    Oct 5, 2013
    Posts:
    35
    Yeah this was great but seems totally busted on 2018.2.6 :( Even says the Example Prefab is broken
    HALP lol
     
    Last edited: Sep 8, 2018
  23. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @peanutgallery You might need to downgrade to Unity 2018.1.9f1 (That's what I'm using and it's working.

    Hopefully @PhilSA will reappear around here soon as well!
     
    peanutgallery likes this.
  24. RogDolos

    RogDolos

    Joined:
    Oct 16, 2012
    Posts:
    42
    @peanutgallery I just purchased and it appears to be working in 2018.2.6 for me (and now 2018.2.7 as well) on a fresh project. Perhaps try a re-import?
     
    peanutgallery likes this.
  25. peanutgallery

    peanutgallery

    Joined:
    Oct 5, 2013
    Posts:
    35
    Hm, yeah. I just created a new project in 2018.2.7 and it worked after some updates. Gonna have to import stuff one by one and see what's breaking it. Still, that's a big relief!

    Edit: On further testing, it seems like maybe just the prefab is broken. It seems to have happened when I installed the ProBuilder package, but that could be coincidence I suppose. Gonna try building the controller from scratch and see what happens.

    Edit 2: The prefab in the Examples folder "ExampleCharacter" is definitely broken. But I went into the example scene and made a prefab out of the character there and it worked. I do think ProBuilder may break it though, as that was when it wanted to "update the scripts."

    Edit 3: Got ProBuilder in without it breaking this time. Not sure what's different. For now I'm stumped as to what broke it before. I do know there are warnings about some stuff being obsolete, but those are just warnings... right? :p
     
    Last edited: Sep 10, 2018
  26. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    I already have most of my game networking in place, and am just trying to get this character controller working with my existing setup. I'm also trying to manually tick the character controllers.

    The problem I'm having is that after I have multiple players connected, they are running 2x as fast as they should. I assume this is because each player is telling the KinematicCharacterSystem to tick, resulting in 2x the number of simulations at a time.

    What is the correct way to handle this? Do I need to manually disable Character Motor's so I don't end up ticking the same character controller more than the one time?

    Any advice would be appreciated, been stuck on this all weekend :/
     
  27. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    126
    I have a character controller that runs around on a surface that is just a mesh collider. Every once in a while I see this

    Code (CSharp):
    1. rigidbody.position assign attempt for 'Player(Clone)' is not valid. Input position is { NaN, NaN, NaN }.
    2. UnityEngine.Rigidbody:set_position(Vector3)
    3. KinematicCharacterController.KinematicCharacterSystem:Simulate(Single) (at Assets/KinematicCharacterController/Core/KinematicCharacterSystem.cs:225)
    4. KinematicCharacterController.KinematicCharacterSystem:FixedUpdate() (at Assets/KinematicCharacterController/Core/KinematicCharacterSystem.cs:182)
    and am not really sure what the cause might be. Any suggestions would be appreciated.

    Update for posterity: It turned out that the force pushing my character forward was pointed down slightly and would occasionally punch the character into the ground and then cause the exception above.
     
    Last edited: Nov 3, 2018
  28. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @katumplet Unfortunately no, I've emailed as well.
     
  29. eXiin

    eXiin

    Joined:
    Dec 23, 2013
    Posts:
    63
    he's answering on the other plugins he's doing
     
    slimshader likes this.
  30. GorkaChampion

    GorkaChampion

    Joined:
    Feb 6, 2018
    Posts:
    103
    Hi, same issue here using also Dynamic Water Physics on a No Kinematic Rigibody Boat. The character moves the boat as translating some no predictable forces to the boat so the boat leans and move erratically. I bought this controller only for the time the character is walking on the deck as I thought this would be the solution (I use Invector for the rest of the time). I have tried the link above but not luck at the moment....
    Did anybody got a solution on this? Any Idea?Thanks!
     
  31. baumxyz

    baumxyz

    Joined:
    Mar 31, 2017
    Posts:
    107
    Hi @PhilSA.
    First of all: If you are not feeling well or have other worries, take the time you need! Nevertheless it would be nice if you could tell us if this project will continue to be supported by you. Thank you.
     
    Guacamolay and rxmarccall like this.
  32. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    I've been attempting to follow the networking walkthrough example, and realized that if I even just build this example, the clients movement doesn't register on the Server. I was racking my brain wondering what I was doing wrong! Just a heads up in case anyone else is experiencing a similar issue
     
    JustASloth13 likes this.
  33. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,443
    Just getting started with the KCC. Some initial observations, after having browsed the Walkthrough scenes.

    * maybe add a 3D Text in each scene, like the playground has, to explain the WASD/Space/Q/C/E keys introduced (I had to look in the source code to try each scene)

    * in the ladder example, mounting at the bottom of a vertical ladder seems pretty difficult to get right; it tends to attempt to attach and immediately detaches again (angled ladders work easily, as does mounting from the top); not sure what to fine-tune to make this reliable

    * some initial compile errors and warnings should get cleaned up (NavMesh, Networking)

    * the "Root" subelement in the Boat fbx has no polygons, so Unity 2018.2 whines about being unable to calculate tangents without normals; kinda Unity's fault but hard to find which fbx had the error. I adjusted the default FBX import settings on the Boat to calculate normals instead.

    And lastly a question.

    I have a character which the user can sometimes attempt to drag by position (mouse, touchscreen, etc.), but it still has to honor the collisions rigorously. So I will be trying to figure out how to provide a velocity which moves towards the desired position, properly sync'd with whatever timescale/fixedupdate/deltatime is being used. Is there a way to move the KCC by position rather than velocity, similar to the way the PhysicsMover class works? Or is it pretty buried that KCC must be velocity and PhysicsMover must be position based?
     
  34. joaobsneto

    joaobsneto

    Joined:
    Dec 10, 2009
    Posts:
    152
    Do you store distance from ground information so I can use without making a raycast?
     
  35. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    He does store rich data about collisions, quite a lot, but currently I do not see him respond to this thread much. I have the asset and can confirm it's well documented and it's clean code. I'm not sure it actually needs much support - it does say it's best for programmers to dig into. I enjoyed looking through it even if ultimately I did roll my own solution.

     
  36. a352614834

    a352614834

    Joined:
    Nov 17, 2017
    Posts:
    1
    Code (CSharp):
    1. if (Physics.ComputePenetration(
    2.          Capsule,
    3.          TransientPosition,
    4.          TransientRotation,
    5.          _internalProbedColliders[i],
    6.          overlappedTransform.position,
    7.          overlappedTransform.rotation,
    8.          out resolutionDirection,
    9.          out resolutionDistance))
    10. {
    11.      // Resolve along obstruction direction
    12.      // ??????????
    13.      Vector3 originalResolutionDirection = resolutionDirection;
    14.      HitStabilityReport mockReport = new HitStabilityReport();
    15.      mockReport.IsStable = IsStableOnNormal(resolutionDirection);
    16.      resolutionDirection = GetObstructionNormal(resolutionDirection, mockReport);
    17.      float tiltAngle = 90f - Vector3.Angle(originalResolutionDirection, resolutionDirection);
    18.      resolutionDistance = resolutionDistance / Mathf.Sin(tiltAngle * Mathf.Deg2Rad);
    19. ...
    20. }
    what is the code used for in UpdatePhase2() KinematicCharacterMotor.cs?
    Can any one explain it.@PhilSA
    Why modify resolutionDistance,
    the resolutionDirection = GetObstructionNormal(resolutionDirection, mockReport) mean??
    why not resolutionDistance = resolutionDistance * Mathf.Sin(tiltAngle * Mathf.Deg2Rad)
    Thanks!!!
     
    Last edited: Sep 27, 2018
  37. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @hippocoder
    Perhaps you can help me with this question....
    I'm attempting to implement basic client side prediction & reconciliation following 'gabriel gambettas' popular post.

    The Kinematic Character Controller docs say this about Manual Simulation:
    This makes sense to me, but I have one concern.
    When calling KinematicCharacterSystem.Simulate(), this "ticks" and simulates ALL character motors at the same time. I assume for this reason, the example code keeps a history of world states so that when we need to "rewind", we know the state / inputs of all characters (because it ticks / simulates them all at the same time)?

    Finally, for my question.... do you know if there is a reason that KinematicCharacterSystem tick's all character motors at the same time? I was considering modifying it so that I could tick / simulate a single character motor at a time so that when I need to reconcile a player with the Server state, that I can run the Simulate code on just that character and not need to keep a history of other character states / inputs.

    I hope what I'm asking makes sense, or perhaps I'm totally confused?
    Thanks!

    *Update: I found an older post in this forum where a similar question was asked. Apparently there is a overloaded method for Simulate that takes and array (subset) of character motors. I'm going to attempt to use this for ticking my characters individually.
     
    Last edited: Sep 28, 2018
  38. EliotVR

    EliotVR

    Joined:
    Jan 12, 2017
    Posts:
    14
    Hi I'm using KCC ver 2.3.0.

    I found network error in the 18- Networking example.

    For example, A Player(server) made a server.

    And then B Player(client) connect to the server.

    B Player tried moving around character in the scene.

    Client side(B Player) character synchronization is well.

    But server side character synchronization is wrong.

    All character synchronization is work well in the client side.

    But server side synchronization is wrong except server player character.

    https://imgur.com/a/LfF9jxp
    server side

    https://imgur.com/a/L3y4cXD
    client side

    And then I fixed KinematicCharacterSubsystemState script

    Code (CSharp):
    1.   private void UpdateInterpolation()
    2.         {
    3.             // Handle interpolation
    4.             if (Interpolation)
    5.             {
    6.                 foreach (var c in Characters.Values)
    7.                 {
    8.              
    9.                     float interpFactor = (Time.time - c.FromInterpolationPoint.Time) / (c.ToInterpolationPoint.Time - c.FromInterpolationPoint.Time);
    10.                     if (!float.IsNaN(interpFactor))
    11.                     {
    12.                         Vector3 interpPos = Vector3.Lerp(c.FromInterpolationPoint.Position, c.ToInterpolationPoint.Position, interpFactor);
    13.                         Quaternion interpRot = Quaternion.Slerp(c.FromInterpolationPoint.Rotation, c.ToInterpolationPoint.Rotation, interpFactor);
    14.  
    15.                         // Commented this line.
    16.                         //c.MeshRoot.SetPositionAndRotation(interpPos, interpRot);
    17.                     }
    18.                 }
    19.  
    20.                 foreach (var m in MovingPlatforms)
    21.                 {
    22.                     float interpFactor = (Time.time - m.FromInterpolationPoint.Time) / (m.ToInterpolationPoint.Time - m.FromInterpolationPoint.Time);
    23.                     if (!float.IsNaN(interpFactor))
    24.                     {
    25.                         Vector3 interpPos = Vector3.Lerp(m.FromInterpolationPoint.Position, m.ToInterpolationPoint.Position, interpFactor);
    26.                         Quaternion interpRot = Quaternion.Slerp(m.FromInterpolationPoint.Rotation, m.ToInterpolationPoint.Rotation, interpFactor);
    27.  
    28.                         m.Mover.Transform.SetPositionAndRotation(interpPos, interpRot);
    29.                     }
    30.                 }
    31.             }
    32.         }
    c.MeshRoot.SetPositionAndRotation(interpPos, interpRot); this line is commented.

    And then both side synchronization is work well.

    Is this proper solution?

    Thank you for reading
     
    Last edited: Oct 1, 2018
  39. NecroToad

    NecroToad

    Joined:
    Oct 27, 2014
    Posts:
    8
    Hey guys,

    I have not bought this product yet because I have some doubts, but as @PhilSA is not responding I would like to know if any of you could help me:
    1 - Is this Asset compatible with Unity 2018.2.x?
    2 - Can I use Box Collider and other Unity's Colliders as well or am I stuck with Capsule Collider only?
    3 - Imagine two characters walking then they collide with each other and stop. Is it possible that they just stop without one applying force to the other and start 'pushing' it, or will they always end up applying force to each other? In short, is it possible to create "is collision? then stop" kind of behaviour without one body applying force to the other one in the process?
     
  40. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
    Has anyone got any experience tying this in with UMA?
     
  41. Shturmovik

    Shturmovik

    Joined:
    Nov 5, 2014
    Posts:
    29
    While trying to keep the hope alive that @PhilSA hasn't abandoned this fantastic system completely, I'll chime in with some unofficial "support":

    @NecroToad
    1: Definitely compatible with Unity 2018.2.x
    2: Capsule collider only, I'm afraid. I believe there are some discussions earlier in this thread about this.
    3: Should be possible, but will probably require some custom scripting. Sounds like you're talking about AI-controlled characters?

    @CaptainMurphy
    Was planning to test it with UMA, but considering the current status of KCC I've decided to put it off and see what the future brings. Shouldn't be too hard to do at a basic level since KCC doesn't really deal with character models as such, but there are probably some details I haven't thought of. Might still give it a try once I've polished my character ability system a bit more - and will of course post results here.

    KCC is a superb system, so thank god for complete source code in the current situation!
     
  42. Shturmovik

    Shturmovik

    Joined:
    Nov 5, 2014
    Posts:
    29
    BTW, here's a screenshot from a few weeks back of an AI vs AI test scene I've been working on to polish my character ability system and integration with Behavior Designer. Strict root motion for the animations and it works great. Not giving up on KCC even if we're on our own now!
    Greberon 2018-08-20 21-36-40-51.png
     
    Last edited: Oct 11, 2018
  43. baumxyz

    baumxyz

    Joined:
    Mar 31, 2017
    Posts:
    107
  44. sebsmax

    sebsmax

    Joined:
    Sep 8, 2015
    Posts:
    118
    For me, I've moved on... I'm using ECM
     
  45. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
  46. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @baumxyz I've emailed Phil multiple times, sent him DM's on the Unity forum, and haven't heard a word from him. Pretty dang frustrating, I can't recommend this asset when the dev has abanonded it and won't provide any support for it. I've been trying to get support from him for over 2 months now.
     
  47. slimshader

    slimshader

    Joined:
    Jun 11, 2013
    Posts:
    187
    Same here, tried 2 times on forums and also on twitter. Funny party is, he is checking the forums here few times a day. Shame.
     
  48. JSwigartPlayful

    JSwigartPlayful

    Joined:
    Feb 29, 2016
    Posts:
    18
    Anyone extended the KCM to add support for KCM vs KCM push effects? Similar to how there is RigidBody interaction types for pushing rigid bodies, there doesn't appear to be any support in resolving a push effect between multiple KCMs.

    I tinkered with it a bit by adding an alternate code path in ProcessVelocityForRigidbodyHits which calculates and adds a push velocity to the pushed object, but the KCM doesn't simulate in a manner that is truly compatible with KCM pushing.

    Since you ultimately pass in a single velocity to the KCM to simulate, it will not be able to correctly resolve the push effect properly.

    For instance, if I have a large KCM moving at (5,0,0), if it runs into a player that is not moving, it will begin pushing them. The problem is that the moment the player starts running towards the bot, say at (-5,0,0), all pushing stops, which isn't physically correct. That (-5,0,0) velocity should be clipped in the KCM simulate, and then effectively the push velocity integrated as a secondary velocity in order for it to resolve correctly. If the player KCM tries and fails to push an immovable object, they should still recieve the full push velocity. Instead, since the interface is a very simplistic single velocity, these 2 example vectors would just cancel each other out.
     
  49. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Has anyone else in this thread successfully used KCC for networked gameplay?
    I've spent weeks better understanding the networking example and ultimately converting it over to TNet.

    Everything is working for me except that my player's position snaps up into the air when a Jump command is received on non-owner clients when they receive the GlobalSnapshot, rather than smoothly performing a jump.

    My assumption is that perhaps ForceUnground() is being called after the character position was updated rather than before? (I've confirmed it's being called, but perhaps timing is the issue)

    I've been stuck on this forever, is anyone out there that could help me?
    I'm at the point that I'd pay some $ if there is anyone that can help me out!
     
  50. Lex

    Lex

    Joined:
    Dec 2, 2009
    Posts:
    43
    I think it might not be a problem with the KCC itself but the way your interpolation is done. To be honest you don't even need KCC on proxy characters as long as you sync/interpolate their position correctly.