Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

░░░░░░░ Kinematic 2D (v2.1.0) ░░░░░░░

Discussion in 'Assets and Asset Store' started by lightbug14, Jan 30, 2019.

  1. lightbug14


    Feb 3, 2018


    Links: WebGL Demo | Asset Store

    User Manual
    Release Notes


    Kinematic 2D is a Fully Kinematic (non-physics based) 2D Character controller solution that allows you to do the movement of your 2D character while handling collisions.

    Some of the main characteristics are:
    - it offers the functionalities the default Unity Character Controller offers and many more.
    - It was designed only for two dimensional movement (2D).
    - The character body shape is a box (instead of a capsule shape, this is great for platformers).
    - The collision detection method works with 2D and 3D colliders.
    - Designed with rigidbody interpolation in mind, you can choose between three availables types of operation modes: "Transform", "Rigidbody Non-Interpolated" and "Rigidbody Interpolated".
    - Really good performance, (tested on desktop with 500 2D interpolated moving characters, resulting in >300 fps without Vsync).


    This asset was initially designed for 2D platform games (platformers) in general, although you can use it in some clever way and make it work the way you want (like for example a top-down 2D game).


    - The Core: The main part of the package, it does the heavy lifting regarding collision detection and movement in general.

    - The Implementation: Consist of a bunch of components that implement the functionality of “the core” (Input, movement handling, animation, AI). This part of the package acts as an example implementation of the Core, although it’s super handy and useful. It include a character state machine, some useful abilities, and more.

    - Extras: A bunch of scripts with some useful functionality (Platform controller, 2D Camera, etc)

    - Walkthrough: 26 dedicated scenes included with the aim of introduce the main features of the package (Core and Implementation).


    The main difference with others character controllers out there is that Kinematic2D uses a combination of Boxcast and Raycast methods to detect collisions, this means not only fine precision but performance. The Boxcast solution is great for complicated shapes and it is very efficient.


    Even if everything works just fine from the get go It's recommended to have at least some basic C# programming skills (intermediate level recommended) to take full advantage of the asset, for example to extend the character controller, add new states or new abilities, customize the animation system, create the AI, etc.



    - Completely Kinematic.
    - Box-based collision detection.
    - Raycast and Boxcast collision detection methods integrated.
    - No GC Allocations.
    - Can handle steps.
    - Can handle slopes.
    - Can depenetrate from moving/rotating colliders - The character will never go through walls.
    - Supports moving and rotating platforms.
    - Ground clamping.
    - Orientation friendly (this means that you can move your character perfectly in any orientation, good for gravity shifting scenarios).
    - Ground alignment.
    - Vertical alignment modes (this allows you to set the vertical axis of your character, independet from the ground alignment).
    - Independence between Collision Shape and Character Graphics.
    - Facing direction modes, "Rotation" and "Negative local scale" with individual Yaw and Roll parameters.
    - Fully commented C# Source Code.
    - Tooltips available.


    - Chraracter controller implemented as a state machine with separated abilities.
    - External movement data (scriptable objects) allowing pluggable movement behaviours. - Create Movement Areas (also called "environments"), such as water, ice, honey, etc (this affects the horizontal and vertical movement parameters separately) - Configurable horizontal movement.
    - Configurable vertical movement.
    - Precise Jump.(as many as you want)
    - Cancel jump with the release of a button.
    - Air control.
    - Crouch
    - Precise Dash.(as many as you want)
    - Input based Dash (inspired by the game “Celeste”).
    - Wall slide.
    - Input based Wall Jump.
    - Wall and Corner alignment.
    - Action-based movement, not input based ( useful when integrating the AI).
    - AI behaviours, customizable via scriptable objects.
    - Create your custom abilities by right clicking on the Project View.


    - Characters: Boxy2D , Boxy3D and Roboto (animated).
    - Moving/Rotating Platform Controller.
    - 2D Camera.
    - FPS Counter.
    - etc.


    Final Note

    Please, if you have any questions feel free to send me an email and ask me anything, i'm open to answer to your questions about what this asset can or can not do.
    Last edited: May 20, 2019 at 8:23 PM
  2. lightbug14


    Feb 3, 2018
    New version available!



    - Added Support for Interpolated/Non-Interpolated movement.
    - Added "Update Method"(you can choose between Update/LateUpdate or FixedUpdate to move the character).
    - Added Support for rotating platforms.
    - Added "Slope Alignment" feature.
    - Added "Corner Alignment" feature.
    - Added "Wall Climbing" feature.
    - Added Depenetration modes.
    - Added AI Behaviours (via scriptable objects).
    - Added rotation parameters to the platform controller.


    - New classes dedicated to 2D/3D collision detection.
    - Now the actions are sent to the character controller component by a "Character Brain" component (Human brain and AI Brain).
    - Namespaces: All scripts have their proper namespace.


    - Wrong resulting position when creating a character from the asset creation menu (Create/Kinematic 2D/...)
    - Now the handles are drawn correctly without lag.
    - Overall improvements in the collision detection algorithm.
    - Cleaner code.
    - Cleaner demo scenes (more organized hierarchy).
    - Cleaner directory and assets.
    CHEMAX3X likes this.
  3. lightbug14


    Feb 3, 2018
    Minor Version Update



    - Bug in the "WallClimb" feature.
    - Bug in the "Performance" Scene, the "prefab instantiator" didn't stop at the target number of characters.
    - Bug in the "Performance" Scene, the Stop button didn't stop the coroutine.


    - Minor modifications to the 2D and 3D demo scene.


    - Minor improvements in the code.
    - Some corrections to the starting guide.
  4. bravery


    Mar 26, 2009
    This package look promising and interesting.

    However how easy it is to extend this package to include more features?
    Like you have mentioned above that you can use it to build games like Hollow Knight or Celeste , but as you know these 2 games have more player features like in Celeste you have Dash in 8 directions and in Hollow Knight you can melee attack in 3 direction (front, up and down), also Super Meat Boy you have an Air controller where you can change the jump direction while you are in the air... etc.

    So how easy it is to extend this package and build such a features?

    lightbug14 likes this.
  5. lightbug14


    Feb 3, 2018
    Hi, thanks! The main goal of the asset is to offer just a "Move method", if you are familiar with the Unity default character controller component you know what i'm talking about, if not, is just a method that puts the character in X position, while handing collisions, simple as that.

    So, if you want to do a three direction air attack (like in Hollow Knight, the attack behaviour is completely independent of the movement behaviour), swimming ability, the new climbing feature that will define your game, or whatever custom feature you are thinking of you will have to manage the velocity vector of the character yourself,. The character motor is already defined, based on grounded/air behaviours that I have imposed (All suggestion are welcome of course).

    The rest of the package is based on my custom implementation. Of course this is the part is when the usual customer is interested, add this ability, add that new feature, etc.

    Again, with the Hollow knight 3 dir air attack example, you could force the velocity vector to zero when an attack action is performed.

    It is coming a little doc about the implementation, in order to explain things better, maybe with a couple of examples/tutorials.

    Kind regards.
    Last edited: Feb 20, 2019
  6. luispedrofonseca


    Aug 29, 2012
    Great looking package.

    How does it handle moving platforms? Can it handle the player grabbing to the side of a moving platform?
  7. bravery


    Mar 26, 2009
    Thanks for the answer, I have been playing with multiple 2D platform packages from the asset store but always the biggest challenge is how easy it is to extend it, all the packages owners claim that their packages is easy to understand and extend but once you start trying to extend, will not take long time to know that this is not true and you will start facing a lot of complexity issues that will make you surrender and search for something easier.

    So a couple of questions:
    1- How easy it is to understand and extend (because if you did not understand you will not be able to extend)?
    2- Does the package support colliding with any 2D collision? like for example tilemaps and such?

    Thank in advance
  8. lightbug14


    Feb 3, 2018
    Hi Luis, the moving/rotating platform feature is quite straightforward, every time the character is grounded it store the ground information. Every Update/LateUpdate/FixedUpdate (whatever method you choose) the character will update this information and based on the position/rotation change and will perform the action needed. The only caution the user must have is to put the "platform" execution order before the Character execution order. With the LateUpdate is really easy, put the platform in updates, the character in LateUpdate. Another approach is to simple make a "system", this system will perform all the movement for the characters/platforms for you, a nice alternative.

    Let me ask you, Are you Luis Pedro Fonseca from the Reddit post? if so, thanks for the suggestion on the rotating platform, because of that i've implemented it.

    Exactly, that's why i keep saying that this is not "an engine", I tried to limit myself to the "Move method", but also include my little implementation, nothing fancy, just as an example. In previous versions (not released) i had a proper state machine, you could add abilities and states to the character, but that wasn't the initial goal, so i removed it ... who knows, maybe i could include this feature as a "new implementation", that would be cool.

    1 - It depends, the starting guide that i included explain how the character moves, maybe it's not 100% clear, but at least it's 85% clear (i'm working on that), although the interface between you and the whole asset is just the Move method, you should not modify the character motor, character physics, etc.

    2 - Yes It does, with any type of collider, box, circle, composite, etc. Also 3D colliders.
    Last edited: Feb 21, 2019
  9. luispedrofonseca


    Aug 29, 2012
    @lightbug14 Thanks for the explanation.

    In my case I'd like to "attach" to a moving platform, but the character wouldn't be grounded. Imagine the player is on a sticky wall that moves. Would that be possible?

    Also, do you expose the current character collision information? I'd need to know if the player is colliding on top/bottom, left/right.

    P.S.: Yes, I commented on your Reddit post a while back. Glad to see you implemented my suggestion! ;)
  10. lightbug14


    Feb 3, 2018
    The answer is "mostly yes", currently there is an internal struct like this:

    Code (CSharp):
    1. /// <summary>
    2. /// Container of information regarding the collision process.
    3. /// </summary>
    4. public struct CollisionInfo
    5. {
    6.     // Ground Info
    7.     public GameObject m_groundObject;
    8.     public int m_groundLayer;
    9.     public Vector3 m_groundNormal;
    10.     public Vector3 m_groundContactPoint;
    12.     // Collision flags
    13.     public bool m_bottom;
    14.     public bool m_top;
    15.     public bool m_left;
    16.     public bool m_right;
    18.     // Slope hitInfo
    19.     public float m_slopeSignedAngle;
    20.     public float m_slopeAngle;
    21.     public float m_slopeAngleSign;
    22.     public bool m_onStableGround;
    24.     // Slope hitInfo
    25.     public float m_wallSignedAngle;
    26.     public float m_wallAngle;
    27.     public float m_wallAngleSign;
    29.     //Movement
    30.     public Vector3 m_groundMovementDirection;


    there are properties related with the current state, for example:

    Code (CSharp):
    2. public bool isGrounded
    3.     {
    4.         get
    5.         {
    6.             return m_info.m_bottom;
    7.         }
    8.     }
    10. public bool isAgainstLeftWall
    11.     {
    12.         get
    13.         {
    14.             return m_info.m_left;
    15.         }
    16.     }
    19.     public bool isAgainstRightWall
    20.     {
    21.         get
    22.         {
    23.             return m_info.m_right;
    24.         }
    25.     }
    All of these properties are related with the top,bottom, left, right and slopes, they have nice names (isGrounded <--> bottom = true). The "mostly yes" is because initially i used this values only for internal purposes, but recently some people had sent me about this request. In 1.2.2 i will expose everything at 100%, probably right now is "Ok", but in the next release i will do things right with an online API reference, once and for all!

    Short answer: Possible? yes, but not by click two buttons, i mean, there isn't a method like "stick to the walls", at least not internally in the characterMotor, but, you can do it on your own implementation (i know is not a nice and promising answer). In the description of the package, by "you can use it in some clever way and make it work the way you want" i meant this type of situations. This is an interesting feature, i could implement this behaviour, trigger the moving platform stuff not only with the grounded state but with the left/right state... I will consider it.

    Sorry i missed your previous question about the "grab", i guess it is related to this matter.

    Last edited: Feb 21, 2019
  11. bravery


    Mar 26, 2009

    Sound good,
    So I'm in, will buy it and check how easy it is.
  12. bravery


    Mar 26, 2009
    I'm now trying to follow your starter guide I reach the topic(CREATING A BASIC CHARACTER) , however I'm not able to find the character you are using in the documentation the only thing I found is drawing1.png in the folder (Kinematic2D\Demo\Characters\Roboto\Sprites) but the problem with that sprite is that it's scattered and not ready like the one you present on the document !

    So it will be good practice to include the asset in the tutorial in your package so it will be easy to follow.
  13. bravery


    Mar 26, 2009
    Hi lighbug,

    I just finish reading the starter guide, and I'm sorry to say it's far away from being 40% complete (you mentioned to me that it's 85% complete), and here is why I'm saying that:
    1- The document show a rough example of how to setup a character but the example does not explain for example when and why to add a rigidbody2d (this component is there in all the prefab examples).
    2- The 2D playercontroller you have no mentioned anything about it and not explain any of it's parameters.
    3- regarding the section 5.1 "move method" and section 5.2 "GROUNDED VS AIR MOVEMENT" the explanation is so much abstract explanation, you will need to give at least an example how to implement the things that you are writing about.
    4- The features what you called implementation features these are not explained at all.

    Hope you will used these points as advise to improve your getting started guide, and let me suggest something here, try to make video recording (host in youtube) to explain things, that will save you a lot of time on writing, and for us always seeing examples is better that reading too much pages.

    Now see for me I want to understand your code (because if I did not understand it I will never be able to extend and add my own features), so where should I start reading? and in what order?

    Like you have 3 folders that look important:
    1- Character Implementation: this one include 2 folders one is "Scripts" and second is "Scriptable objects" and inside the second one there are two folders "AI behavior " and "Player input" What are these?
    2- Core: This one include many scripts.
    3- In the Demo folder there is a script folder as well that include many scripts.

    So Where should I start read to learn the underlying structure of this component? and in what order?

    Appreciate you support to get the required benefit of the package.

  14. lightbug14


    Feb 3, 2018
    it's funny, because yesterday i was looking to put into the scene this character and i couldn't find it. The character "Roboto" was in 1.0, he was a test character, for 1.2.0 i put a new character "Boxy", it's like the default, for the keyImages and everything, for 1.2.2 (i'm going to update tomorrow) i'm putting back Roboto, (a Prefab of the character), i really don't know why I have removed it.

    The guide has the following purposes:
    1 - Explain the character motor parameters (i am aware that are some missing, i am working on that)
    2 - Make clear one thing: "use only the move method", that's your entry point.
    3 - Explain the basics of the boxshape (air vs grounded).
    4 - Explain the two components of the input vector.

    Remember that the "extend the character controller" part in the description is inside the section "Requierements" as a suggestion based on the C# knowledge: "It's recommended to have at least some basic C# programming skills (intermediate level recommended) to take full advantage of the asset, for example to extend the character controller, add new states or new abilities, customize the animation system, create the AI, etc."

    By "full advantage" i meant that if you know some basic/intermediate C# you could go inside the Character Controller and adapt it to your liking, maybe create a new one based on this structure, or whatever (a not being attach only to the "Move" part). Look that "extend the character controller" is not part of the "features" part.

    Because that's an implementation that i came up, it was never intended to be an "official" package. But (as i poorly predicted) people is interested in this part more than the collision part, so i receive a lot of "can yo do this?" "can yo do that?" and i'm started to put more effort in this Character Controller (from >1.2.2), this "effort" include a better guide/tutorials/doc.

    Think of this part like a helper, a "what you can do" with the character motor (and the rest). As I said in previous post (i think, sorry if i'm wrong, too many mails), i will in include a guide exclusively to this implementation.

    Anyway, almost every parameter has a "Tooltip".

    It isn't so abstract to me, maybe i'm wrong, here is what i said in the doc:

    " The Move method is the main interface between any script and the CharacterMotor, and it would be
    your only entry point. It takes a Vector2 variable as an input argument and a “deltaTime” float (could be
    a frame deltaTime or a fixed deltaTime).

    The input vector corresponds to an increment/decrement of local position, or “deltaPosition”."

    For the starting guide purpose this is the thing you should know about moving the character (the method at least), works the same that the default Unity character controller component. For the behaviour of the character on slopes see the parameters section.

    I agree with the implementation part, that's why the "85%" i mentioned, that section act as a simple explanation of the two components of the input vector and the effective box shape of the character while moving in the air/grounded, with that in mind you have an overall idea how the character shape will collide with the world, that's really "the meat", for a character design you don't need to know more than that (this + the tooltips should he enough).

    Again, i agree, this section need a mini example and is being currently modified.

    Ah, maybe i missed this part! i admit it, that's on me, thanks for point that out!. Just to be clear, if you are moving your character via Rigidbody.Move o Rigidbody.position you need a Rigidbody (2D / 3D).

    Explained how? I thought they were self explanatory:

    - Configurable horizontal movement. (can configure the horizontal movement)
    - Air control. (how much control the character has in the air, close to 0 -> super meatboy , 1 -> hollow knight)
    - Multiple Jumps. (more than one jump)
    - Cancel jump on release of a button. (if you release the button the "jump" is canceled)
    - Multiple Dash (with animation curve). (more than one dash)
    - Input based Dash (inspired by the game “Celeste”). (dash based on the current input)
    - Wall slide. (you can do wall Slide)
    - Input based Wall Jump. (wall jump based on the current input)
    - Action based movement, not input based. (You won't find a "Input.GetKey" inside the character controller)
    - Choose the "Update method" ( Update, LateUpdate or FixedUpdate) with just one click.
    - AI behaviours, customizable via scriptable objects.

    Of course, feel free to keep posting about this or send me an email, it will help the package, me and the customers.

    Ok, nice question, if you want to understand the whole package first read the starting guide, that guide is there for you in order to do a custom implementation. Once you get that start from the top to the bottom. The structure works like this:

    Character Human Brain (or maybe the AI Brain) --> Character Controller 2D --> Character Motor

    1 - Go to the character brain (Human or AI). In this component the input is updated and sent to the character controller 2D, in the form of an actionValue struct. The input (of course) is independent of the motion update method (update, fixed, etc).

    Code (CSharp):
    1. m_characterController.SetCharacterActionInfo( m_characterAction );
    2 - Go to the character controller, here you have (v1.2.1):
    Code (CSharp):
    1. protected override void UpdateBehaviour(float dt)
    2.     {
    3.         UpdateState( dt );
    5.         m_characterMotor.Move( m_velocity * dt , dt );
    7.         if( m_characterAnimation != null )
    8.             m_characterAnimation.UpdateAnimation();
    10.         if(!m_characterBrain.isAI())
    11.             ResetActions();
    13.     }
    (Don't worry about the protected override, the "customBehaviour" do the update work)

    2.1 - UpdateState will manage the states based on the current action value. This is currently a big switch, go inside a take a look, it's nothing fancy/complicated. If you want to add a new state (specifically for this implementation in v1.2.1) do the following:
    2.1.1 - Go to line 13 and add your state:

    Code (CSharp):
    1. public enum CharacterState
    2. {
    3.     Normal = 0,
    4.     Jumping,
    5.     Falling,
    6.     WallSlide,
    7.     Dash,
    8.     WallJump,
    9.     ShiftingGravity,
    10.     Climbing ,
    11.     MyNewState  //<-----
    12. }
    2.1.2 - Create your "transition" (the way you want) inside the big switch, for example:

    Code (CSharp):
    1. if( m_characterActionInfo.m_dashPressed && m_characterActionInfo.m_jumpPressed)
    2.                 {
    3.                     m_currentState = CharacterState.MyNewState;
    4.                     break;
    5.                 }
    2.2 - Then the character motor will do the "Move function".
    2.3 - The character animation (another implementation of mine) is updated.
    2.4 - if the brain isn't an AI brain the action value will do a Reset So the input will replace the actionValue frame by frame.

    3 - the Move method , and the character motor, well, this is the end of the ride :), inside the character motor you have boxcast/raycast method in order to move properly the character, to do a slide from slopes, etc etc, you should not touch this part of the package , and i think the basics are explained in the starting guide, not at 100%, because the new wallClimb and slopeALignment are not there (for now).

    For the extras part, don't worry about it, these are scripts/helpers that i used to make the scenes, move the platforms, etc. They are there just for the demo scenes, if you want to use them in your project go ahead (the platform component is really helpful) , but they are not the main part of the package. see the demo scenes to maybe "learn" from them, but i wouldn't pay too much attention to this scripts, even some of them are really easy and straighforward.

    Thanks to you, this helps a lot, the feedback like the one you are delivering right now is extremely important. Sorry if the response is too long:).

    For the documentation part in general i ask you for a little patience, i know is too much to ask but currently i'm working on it, tomorrow i will upload 1.2.2 with some modifications requested, along with the Roboto character. For 1.2.3 or 1.3 i will upload a better doc and include the implementation, i promise.

    Kind Regards!
    Last edited: Feb 22, 2019
  15. bravery


    Mar 26, 2009
    Hi Lightbug,

    Appreciate your detailed answer, it was really helpful and appreciate also you co-operation to improve the code / Documentation.

    I enjoyed reading your answer as it give a good perspective about the asset, and now I know where exactly I need to focus (mainly the brain and the 2D controller) to add more features, so I can leave the underlying details for later.

    Now I'm playing around with the 2D player controller, but I notice something when I was playing with the update modes (update, late update, fixed update) I notice nothing changes on the behavior of Boxy while I'm playing the 2D demo scene, so what is the advantage of using this option and when we should use it?
  16. lightbug14


    Feb 3, 2018
    Hi bravery, thanks! i forgot to mention, in order to extending the character controller go to the "brain" and do the input testing that you want first, that information will go directly to this struct, so the first step would be modifying this structure (prepared for the inputs of your game, for example adding a "dashReleased", or a "SuperJumpPressed" , or whatever you want):

    Code (CSharp):
    1. [System.Serializable]
    2. public struct CharacterActionInfo
    3. {      
    4.     public bool m_right;
    5.     public bool m_left;
    6.     public bool m_up;
    7.     public bool m_down;
    8.     public bool m_jumpPressed;
    9.     public bool m_jumpReleased;
    10.     public bool m_dashPressed;
    12.     public void Reset()
    13.     {
    14.         m_right = false;
    15.         m_left = false;
    16.         m_up = false;
    17.         m_down = false;
    18.         m_jumpPressed = false;
    19.         m_jumpReleased = false;
    20.         m_dashPressed = false;
    21.     }
    23. }
    If you want to create custom signals or actions just go inside the struct and create whatever variable you like, in this case i have bools, but they can be floats, ints, etc, as long as you asssign some unity input to them (axis, pressed/released, etc). Then the brain will modify them by testing the Unity inputs frame by frame (or in the case of AI via the scriptable objects actions), here you have to do some "if" (see the code for examples).

    If you don't notice anything is "good", but you will eventually notice something, specially if you put your character in a non-linear moving platform... let me explain (and this is going to be in the Doc, is an important section i'm writing right now):

    This part is there as an underlying structure for motion/update setting, it's just there for support. Currently the character can move in all the possible ways, and can be updated in every update mode. In v1.0 the character was moved by an Update/LateUpdate method, transform.Translate, and that's it, everybody happy (specially my poor brain), but, if you want to sync with the physics world the super fast (or super slow) update world may not properly interact with the dynamic rigidibodies. Also having a lots of characters in scene the fixed update mode is more eficient (we are talking of 600 characters in desktop vs maybe 400 of the update, i know, madness, but still).

    These are the three "valid" combinations: (this is why i said in the HelpBox "Be sure to correspond the..."), although you can combine them the way you want:

    > Motion : Transform, Update : Update/LateUpdate:
    this works 100%, moving and rotating platform look perfect, physics reacts not so perfectly, you could reduce the physics step from 0.02 (50 fps) to 0.016 (60 fps), so with the vsync enabled the difference will be not so noticeable.

    > Motion : RB.non interpolated, Update : FixedUpdate:
    this works 100%, moving and rotating platform " look almost perfect" , they don't look smooth as the previous one, there is so jittery, specially with an "update camera", because you have (by default) 50 fps (the 0.02 from before), physics reacts perfectly.

    > Motion : RB interpolated, Update : FixedUpdate:
    this works (IMO) at 80%, same as the previous setting, looks smooth! but this time the moving and rotating platform tend to look clunky, i don't get why this is happening, the fixed update looks ok, so i expect that the interpolation will do it job, but no, only chaos in extremely situations. Maybe you didn't notice this, by in the two available demos the setting is this one. The physics interaction are perfect, just like the previous setting.

    I'm doing every movement in one call, whether is "Translate" "rigidbody.position" or "rigidbody.MovePosition(---)", the character internally updates a virtualTransform(position adn rotation), then all the collision testing happens, and by the end the "movement call" is made. This is why if you touch the transform of the character directly (from an external scrip) nothing will happen, because you need to update the "virtual transform" too. In 1.2.2 i'm adding a "Teleport" method.

    Here is where the combination may be causing the problem, are the platforms in "Translate"? is the Camera in Update or FixedUpdate? is being interpolated? are the platforms being moved frame by frame? ... In summary, If you have any doubt, go with the Update/Late + Transform, every CharacterController2D that i know (at least 2D) uses this aproach. This is why i said before that "is just there for support", i'm new to the interpolation world, so maybe i am missing something. it works, but use it wisely.
  17. bravery


    Mar 26, 2009
    Hi LightBug,

    I'm trying to create super Dash Just like hollow-knight check this link:

    I notice the way you show me up about, but since there is a Dash already implemented can't we just use it and extend it?

    Can you please advise about that?

  18. lightbug14


    Feb 3, 2018
    Hi bravery, the Dash ability that i made works like this: once you have pressed the "dash" input the current state change to "CharacterState.Dash" plus the ability is setup ("SetupDash"). Inside the dash state the character moves to the left or right with a given speed (based on the animation curve) during a given duration time. This is the default behaviour, you could easily make a constant curveand modify the duration to make the trick. The things is that the hollow knight dash is "infinite" in duration, so to simulate this behaviour you could do the following:

    But there is one more thing, you have to provide an exit to this state (otherwise it will never ends, ok it will ends at 99999.00001 seconds). You could check for the right/left flags of the collision info (isAgainstLeft/RightWall), if this is true return to the CharacterState.Normal state, maybe also check for some input.

    Of course the 99999 is a trick, maybe is not a good idea to replace the normal dash with the super dash. It would be better to replicate the behaviour of the normal dash by creating a new one, the "super dash".

    Also the HK dash has an initial state, like a "charging dash" state.

    Here is a simple state diagram you should follow:

    Code (CSharp):
    3. case CharacterState.Normal:
    5.                 if( superDashPressed)
    6.                 {
    7.                     m_currentState = CharacterState.ChargingDash;    
    8.                 }
    9.               break;
    11. case CharacterState.ChargingDash:
    13.         if(superDashReleased)
    14.        {
    16.               if(superDashChargingTime < dashChargingDuration)
    17.               {        
    18.                         m_currentState = CharacterState.Normal;[/INDENT]
    19.                         superDashChargingTime = 0;
    20.                         break;
    21.               }
    22.               else
    23.               {
    24.                       m_currentState = CharacterState.SuperDash;
    25.                      superDashChargingTime = 0;
    26.                      break;
    27.               }
    29.        }
    31.        superDashChargingTime += dt;
    32.        break;
    34. case CharacterState.SuperDash:              
    36.                 if( hitWall )
    37.                 {
    38.                        m_currentState = CharacterState.Normal;
    39.                        ResetVelocity();  
    40.                        break;      
    41.                 }
    42.               else
    43.               {
    44.                      if(jumpPressed)
    45.                      {
    46.                             m_currentState = CharacterState.Normal;
    47.                             ResetVelocity();
    48.                             ProcessJump();[/INDENT]
    49.                      }
    50.               }
    53.             break;
    This could be wrong, just as an idea/pseudocode.
  19. bravery


    Mar 26, 2009
    WOW Amazing info
    Thanks I will test it and update you.
  20. lightbug14


    Feb 3, 2018
    New version available!



    - UpdatePose method to the character controller 2D component (in order to update the size of the character at runtime)
    - “Crouch ability” to the character controller 2D component
    - “Air depenetration”, now the depenetration algorithm works also in the not-grounded state.
    - Teleport method.
    - Character Debug components ("CharacterDebug_Events" and "CharacterDebug_Info").
    - Events for Left/Right collision: "OnGroundedRightCollision", "OnGroundedLeftCollision", "OnAirRightCollision" and "OnAirLeftCollision".
    - Character prefabs: Roboto (was available only in v1.0) , Boxy2D and Boxy3D.
    - New “MiniGame” scene.


    - Elements of the collision info struct not updating properly.
    - Delegate events not working while the character is in the air.
    - Collision information not updating properly.


    - The collision information from the "CollisionInfo" struct is now fully exposed (via getters).
    - The “Starting Guide” becomes obsolete, now is an online user manual.

    thanks @bravery and @luispedrofonseca for all the suggestions!
  21. bravery


    Mar 26, 2009
    WOW nice update, I just download it need sometime to check it and thanks for the new online documentation seems to be better and include much details.

    By the way I was trying to implement the above super-dash but the main problem I was facing is checking the walls I was using the following
    m_characterMotor.isAgainstLeftWall || m_characterMotor.isAgainstRightWall
    here is the code:

    Code (CSharp):
    1.                 case CharacterState.SuperDash:
    2.                     if(m_characterMotor.isAgainstLeftWall || m_characterMotor.isAgainstRightWall)
    3.                     {
    4.                         m_currentState = CharacterState.Normal;
    5.                         ResetVelocity();
    6.                         break;
    7.                     }
    8.                     else
    9.                     {
    10.                         if (m_characterActionInfo.m_jumpPressed)
    11.                         {
    12.                             m_currentState = CharacterState.Normal;
    13.                             ResetVelocity();
    14.                             ProcessJump(dt);
    15.                         }
    16.                     }
    17.                     setupSuperDash();
    18.                     ProcessSuperDash(dt);
    19.                     break;
    20.                     //Firas End
    But the Boxy2d was not return to normal once touching the wall, I wonder why is that?

    And how can I implement the wallhit using the new version?
  22. lightbug14


    Feb 3, 2018
    Thanks bravery! of course is still growing but is a good start.

    I would recommend:
    - first of all using the new version. One of the release notes says: "Elements of the collision info struct not updating properly." this might be the problem.
    - the code seems to be fine, in any case, add one of the newest "CharacterDebug" components in order to check if this left/right detection is happening (a simple print is also valid). Go to the character object and add a new script : "Kinematic 2D/Core/Debug/Character Info", this will print a GUI Box on screen (like the one in the 2D/3D demo scene) with all the collision information. Check if the left/right flag is working properly (it should now).
    - i don't know what the "setupSuperDash()" method does (this is not the problem for sure), maybe this one should be on the "transition" section of the code (?), i mean, the lines where you change from normal state to superDash state.
  23. bravery


    Mar 26, 2009
    Hi LightBug,

    Thanks for the comments will try that and update you.

    However I'm trying to play the MiniGame Scene, but I'm stuck at the beginning where when-ever I reach the red wall I always return to the beginning, I checked the red walls and found that they have a script called teleport and it's always take me to start point!

    How did you manage to get out of the hole? As at some point the red walls exist at both left and right side at the same time?
  24. lightbug14


    Feb 3, 2018
    The red walls are "traps", they are not pretty right now but the idea is simple: "if you touched them you pay the price", this is why every trap teleports the player to a "checkpoint".

    Use the double jump!

    This demo could be difficult at times, it was intended to be that way.
    Last edited: Feb 27, 2019
  25. bravery


    Mar 26, 2009
    Hi Lighbug,

    I was studding the tutorial you add in the documentation and I manage to create the very simple 2D character controller, and it's moving the 4 directions correctly however it have not collided with any object (all the objects have a collides ) actually I have added my character on the 2dscene.unity after disabling the 2D player that come with the scene (so all the objects have a collider for sure), but my character is flying around things and not colliding with anything, however after looking into my character motor properties i found that any variable that required a layer there is (nothing), and once I tried to compare it with your character layers all you character layer show (Mixed...) but once I opened it I can'd figure our mixed of what?

    So can you please advise how to get this layer thing corrected? so my interaction with the surrounding works OK?
  26. lightbug14


    Feb 3, 2018
    Oh, I totally ignore the layer mask part, later i will improve it. Thanks for notice that!

    Obstacle LM -> left/right/top side interaction
    Ground LM -> bottom side interaction (is collision is going to put the character into grounded state)

    almost in 99.9999% of the usual games this two would be the same (for the "one way platforms" you have a separate LM)

    The character prefabs have already layermasks fields, but as i explained in the "Importing the package" section this could be a mess and depends entirely on your project. I've decide not to upload a whole project so this would result in weird layer mask fields. I'm saying this in case you want to add your own character to the demo scene, remember that all the obstacles and platforms from the demo scenes are using predefined layers, for example if one of those layers corresponds to the layer 14 and you don't have a name for it this layer will not appear in any of the layermask fields.
  27. bravery


    Mar 26, 2009
    So how I should make it work?
    I'm stuck now?
  28. lightbug14


    Feb 3, 2018
    The problem you might have right now is a "layer problem" related to Unity, not mine. In any case use the following names:
    - layer 11 : Level
    - layer 13 : Enemy
    - layer 15 : OneWayPlatform

    (just a few)

    at least with these names you should be able to see some layermask fields (characterMotor inspector).
  29. bravery


    Mar 26, 2009
    Hi LightBug,

    I'm trying to use your 2Dscene to run my custom character and that should be an easy task (else how can I use your asset on custom work which is usually more complicated!) but the layers of your example scenes does not show at all ! so how do you expect us to learn from it?
    Now remember if your code depend on layers so that's something need to be carefully explained so we can use the asset.

    What I'm saying is that if your package does not come with your predefined layers (I believe it should) you should mention them in your documentation (so we can learn from that), and then whoever want to customize that he can do it.

    now thanks for providing few layers in your previous post, but please can list for me the rest as I'm still facing issues like for example even after I add the 3 layers you mentioned:
    1- I can't see what is the mix you have select on the (Physics Layer Mask)?
    2- In (Obstacles layer mask) in you player I can see mixed... however in mine I can see level only?
    3- In (Ground Layer Mask) in you player I can see mixed... however in mine I can see level only?

    So please advise.
  30. lightbug14


    Feb 3, 2018
    It's a tradeoff, i've consider to upload an entire project before, but, meeeh, i don't like it, the end result (for the purpose of this asset) is ugly and this asset is not that big. I'm aware that K2D is pure layers and layermasks (this is why the tradeoff). The layer problem is clearly explained in the manual (the layer section) and every problem related to this matter is (as i mentioned a few times by now) a Unity UI problem (this happens with every asset), you will notice this in K2D because is purely layers and layermasks, but don't worry, i will upload a couple of tutorials about this matter, and explain it better (in the character Motor section).

    1 - If you still want to use my scene and see every layer just go with the ultimate solution, call the layers "0", "1", ... , "30" and "31". Super ugly, but hey, i'm not a Unity UI Developer ( ... for now ).
    2 and 3: I don't know what properties your character has, so i can't really help you. Use item 1 solution,it should reveal everything, i guess.

    --> Let's do this, send me by email all of your concerns, images, layers, layermask, your character properties inspector, and whatever you like. Based on that i will update the doc and of course resolve all of your problems (I prefer an email because my phone rings every time i get one).

    PD: I can't send you every layer, i don't have my PC right now, sorry.
  31. bravery


    Mar 26, 2009
    Hi Lighbug,

    sounds good, I will send to you an email

  32. lightbug14


    Feb 3, 2018
    Hello everyone, version 2.0.0 has been accepted! This is a major update.

    All the Components created with previous versions of the asset (<= 1.3.0 ) won't work propperly. It is recommended to start fresh by deleting all the old content and then updating the package.

    Release notes for v2.0.0:

    Unity version ⇨ v2018.3.2 or higher (read the user manual for more information).


    - The "Character Body" is now a separated monobehaviour component ("Character Body 2D" and "Character Body 3D"), it doesn't belong to the Character Motor component anymore.
    - The "Character Motor" component now updates itself (Update/LateUpdate/FixedUpdate), there is no longer the need to pass a deltaPosition externally ("Move" method) to do the movement (although you can use the Move method as before), now this action is performed internally by reading a velocity field that you can modify directly (just like a velocity change occurs in a rigidbody component).
    - Three "vertical direction modes", now the vertical movement can follow a local direction (transform.up) a custom vertical direction or a direction based on an external reference (reference.transform.position), allowing much more freedom.
    - Better Ground Alignment functionality (with added support for not stable ground).
    - A new Character Graphics component, focused on the graphics part of the character. Now the model/sprite can be rotated (Y axis = yaw) or flipped over (negative scale), independently of the character main GameObject (this comes with new Yaw and Roll parameters as well).
    - Added "Facing Direction modes".
    - Removed some functionally from the Character Motor such as wall climb (now called wall alignment) and corner alignment. These features are now abilities you can drop onto the character.
    - Added an external LayerMask setting profile (scriptable object).
    - Added a “crushed” flag (it works only with depenetration enabled).
    - Removed Physics settings from the character motor. This feature will be re-introduced in v2.1.0 as a more complete ability.


    - A new approach regarding the character states and abilities, now it is possible to add separated abilities to the character.
    - Added Separated Movement Data Scriptable Objects for every Ability, now it’s super easy to change the behaviour with these pluggable data containers.
    - Added "Velocity Areas", this allows you to change the velocity/acceleration of the character by using triggers.
    - Added "Movement Areas", this allows you to change the character horizontal and vertical movement parameters separately by using triggers (useful to set different movement behaviours at runtime to create different movement environments such as water, ice, honey, etc).
    - Added a “Character Ability creator”, this is just an asset menu option “Kinematic 2D/Create Character Ability”. With this tool you won’t need to write the base ability stuffs all the time (not that much code lines, however this is really useful).


    - Code improvements.
    - Better looking inspectors.
    - Custom Icons for the components.
    - Added an entire walkthrough section.
    - bugs fixed.
    Last edited: May 3, 2019
  33. lightbug14


    Feb 3, 2018
    quick bug fix in v2.0.0!

    Bug: Wrong pivot used when jumping with Gound alignment = enabled on a >0° slope.

    Fix: Replace line 1751 from the "CharacterMotor" script (Kinematic2D/Core/Scripts):

    Code (CSharp):
    1. if( isOnRightVerticalSlope )
    with this:

    Code (CSharp):
    1. if( signedAngle < 0 )
    This is going to be included in 2.0.1 (maybe a week or so).

    Thanks Michael!
  34. lightbug14


    Feb 3, 2018
    Hello everyone, version 2.0.2 is available now


    Release Notes:


    - Debug settings(CharacterMotor), now all the debug related fields are organized inside this class.
    - Improved debug gizmos for the Character Motor component, now it is possible to visualize the effects of the following features: Ground Clamping, Ground Alignment, VerticalAlignment(towards and away the reference) and the ground movement direction.
    - “Grounded Velocity Reset” (Slide settings), this will reset the character velocity when it goes from sliding to grounded.
    - “Not Grounded Velocity Reset” (Slide settings), this will reset the character velocity when it goes from sliding to not grounded.

    - Wrong pivot selected when the character is jumping with ground alignment enabled.
    - Slope depenetration bug when the character was approaching a steep slope slowly, this caused the character to be not grounded for a frame (pushing it back abruptly).
    - Bug in the “CharacterMotor” inspector, the “World Vertical Direction” field (Vector3) didn’t adjust correctly when the width of the inspector was reduced.

    - Improved sliding velocity conversion from sliding state to not grounded state, now the “ground movement direction” vector is added to the character velocity (if you want to avoid this just enable the “Not Grounded Velocity Reset” option).
    - Minor modifications and improvements to the Walkthrough scenes.
  35. lightbug14


    Feb 3, 2018
    New update! v2.1.0

    Release notes:


    - The “CharacterController2D” component now derives from the Character Motor component.
    - The CharacterBrain updates itself with the Update method (like it should).
    - The CharacterAnimation component now allows you to override some internal methods in order to use an external animation solution, like for example the Legacy Animation System. Also very important, this component (by default) should be added to the object that contains the animator.
    - The HumanCharacterBrain now exposes some of the basics inputs method (GetAxis, GetButton , GetButtonDown and GetButtonUp ) , allowing you to use the default Unity Input system(by default) or any other system. Also the Input Data (scriptable object) has been updated with names instead of KeyCodes.
    - The animator controller that came by default has been modified by removing all the transitions and most of the parameters. Now the animation clips are played directly with “Animator.Play(...)”.


    - Enum comparison method “Equals” was generating garbage frame by frame. this was replaced with “EqualityComparer”.


    - Velocity Settings (CharacterMotor), this class allows you to set the velocity continuity of the character in certain situations (unstable to stable, unstable to not grounded , grounded to not grounded).
    - “Kinematic2D_Inputs” preset file included (Project Settings/Inputs).

    A small mistake! -------------------------------------------------------------------------------------------------------------
    The CharacterController2D Gizmos are not being updated correctly in the scene, this is because I forgot to set to true the "editorForChildClasses" variable in the CharacterMotor editor. The fix is really simple, go to "Kinematic2D/Core/Scripts/Editor/CharacterMotorEditor" and replace line 9 with this:

    Code (CSharp):
    1. [ CustomEditor( typeof(CharacterMotor) , true ), CanEditMultipleObjects ]
    Last edited: May 20, 2019 at 11:12 PM