Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

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

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

  1. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, to be honest in the current version this is not properly managed, at least not as i wanted to. This has been requested before, this is why it is being implemented in the next version (character vs character collision). A trick you can do now is to put a "character A" inside a particular layer and set that layer as an obstacle for a "character B". You can still trigger events, use collision flags, etc (just like a moving wall). Obviously this scale really bad for more that two types of characters.
     
  2. Biebras

    Biebras

    Joined:
    Aug 21, 2017
    Posts:
    17
    Hey, how about "Just in time jump", I mean, when you fall from a ledge, you have few seconds for a jump, or I need to code by my self?
     
  3. Biebras

    Biebras

    Joined:
    Aug 21, 2017
    Posts:
    17
    And another question. I was trying to implement slide mechanics(when the button is pressed, execute slide) and I have a question about input. Should I go to script and modify(scriptable object, some classes) to add inputs for slide mechanics or should I use Input.GetButton in Character Ability script???

    The last question:
    I modified some scriptable objects, classes, enum for slide. I did something similar in character abilities as in other character abilities scripts(jetPack, wall jump...), the input works, but when I executing it, the gravity doesn't work(it's because it's not normal state??), anyways how could I fix it???
    Could you explain more were to modify scripts?

    Here's my code where gravity doesn't work

    Code (CSharp):
    1.  
    2. public override void Process(float dt)
    3.     {  
    4.         if( movementController.isCurrentlyOnState( MovementState.Normal ) )
    5.         {
    6.             if( characterBrain.CharacterAction.slide)
    7.             {
    8.                 movementController.SetState( MovementState.slide);
    9.             }
    10.         }
    11.         else if( movementController.isCurrentlyOnState( MovementState.Slide) )
    12.         {  
    13.             if( !characterBrain.CharacterAction.slide )
    14.             {
    15.                 movementController.SetState( MovementState.Normal );
    16.             }
    17.         }
    18.      }
    19.  
     
  4. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi @Split3 , yesterday I read your question and totally forgot about replaying :D, sorry!


    Oh damn i forgot about the JIT Jump and the coyote time :D, well that's gonna be on the next-next feature release, sorry again.

    As always you can do it yourself if you want, but you will not get that information from the character motor right now. So, in theory you can do a boxcast (or any other physics query) while the character is falling, check if there is ground below and make the character jump (if some condition met).

    For the coyote time (not quite as i wanted) you can give the character a free grounded jump by considering the not grounded time (after the character left the grounded state), if this value is less than the "coyoteTime" the jump comes for free. Since this is fast, the small amount of negative vertical movement (due to gravity) is not (and shouldn't be) noticeable by the player.
    This can be implemented using the "Implementation" (like i mentioned before) or inside the "Core" (this will be more "Pro"). I will do this using the CharacterMotor (the core) to implemented the the JIT Jump and the coyote time.

    Great question, i should made a simple tutorial about this (I don't have much time these days). I am reworking the entire user manual and web page, including some examples and so on, i will add this to it.

    The best way t odo this is to:
    1. Define a new action inside the CharacterAction struct (look at the jumpPressed etc, clone that behaviour is just a bool).
    2. Create a new inputdata asset with your custom input key/axis in it.
    3. Update that action inside the "CharacterBrain" by reading the inputs. Again look at the others actions.

    I don't recommend to do an Input.GetKey or similar because that's gonna use only the Unity old input manager. If you are good with that go ahead.

    I know it sounds complicated but it's not, send me a mail if you have problems.

    By the way, In the new version all the actions can be added separately, no more "jumpPressed" or "jumpRelesed" etc, now you can create an action "jump", then called jump.pressed. Also you can choose separately your input mode (Unity's, Mobile UI or a custom solution):


    Yes, i believe that's the problem. When you are setting the movement state to "slide" the vertical movement doesn't know about this, the verticalMovement ability is listening to the Normal state, so you will have to do something like this maybe:

    Code (CSharp):
    1. public override void Process( float dt )
    2.     {    
    3.         if( movementController.isCurrentlyOnState( MovementState.Normal ) || movementController.isCurrentlyOnState( MovementState.Slide))
    4.         {  
    5.  
    6. ...
    This implementation's state controller is state/ability based. Based on the feedback i get i think it's better to implement a state based controller, that is, a Normal State, a WallSlide state, etc with their own ability code inside. This scheme allows you to easily control the velocity of each state using only one script rather than separating the velocity across multiple scripts (if you think about it almost every state work like this). This is ready for 3.x.x snf it actually works really great.

    In summary, now if you want to modify this abilities/states you need to:
    1. Create your state
    2. Create your ability
    3. Update your ability, considering the current state. (remember to create the transitions inside, maybe to another state or whatever)
    4. Modify the horizontal velocity and/or the vertical velocity (characterMotor). Beware! if any other ability is writing the same property there will be a problem.
    In the next version:
    1. Create your state
    2. Update your state
    3. If you want to, Implement the CheckTransition method (for the current state and the next)
    4. Modify the velocity, size , etc.
    If you are still having some questions (I'm sure you have), please send me an email, i'll send you some examples.


    Cheers.
     
    Biebras likes this.
  5. ericvrp

    ericvrp

    Joined:
    Nov 20, 2013
    Posts:
    10
    Any progress here?
     
    qua1ity likes this.
  6. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    A lot actually :)

    There are a number of improvements and also a lot of small bug fixes (thanks to all of you who helped me find those).

    Since it's been a while since the last release of kinematic 2D i will release version 2.4.0 (not 3.0.0), is the fastest less buggy way.

    i'm currently trying to polish/fixing the current state of 2.4.0. Version 3.0.0 was much better :( unfortunately it will take a little more time and effort.

    Still, 2.4.0 will be far better than 2.3.X for sure. There are two or three bugs in the way (nothing really serious), other than that it's working fine.


    So, again apologies for the delay :oops:.



    Expect 2.4.0 soon!

    ...but, how soon?

    ... soon. ;)
     
    qua1ity likes this.
  7. TazmanNZL

    TazmanNZL

    Joined:
    May 10, 2014
    Posts:
    4
    Heya,

    I followed the basic debug Tutorial. When moving down with "S" on colliding with the ground Layer is: "Static Obstacle". Pressing W does not allow me to move up off the ground. Before colliding I can move up, down, left and right. It's almost like it's clamping to the Obstacle? I'm using the Kinematic 2d > 2d Character to test with.
     
  8. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, yes, that's exactly the purpose of that mini tutorial, to show you that a not grounded character can move freely in the air. Once this is grounded it will clamp itself to the surface, no matter what (unless the "ground check" becomes "false").

    Sorry if i didn't mentioned that. If you need to get the not grounded behaviour you can use the always not grounded flag (CharacterMotor / CharacterController2D).
     
  9. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    By the way, here are some improvements for 2.4.0 (i know, not a real update). Since i prepared already this video for some users i decided to upload it to youtube.


    1. FixedUpdate + Interpolated (100%) * Bye bye update *
    2. The character can filter the one way platform based on the horizontal collision angle.
    3. The character dynamic movement (due to moving platforms) now considers collisions.
    4. The character will never pass through a platform, even if the speed of the platform is super high.
    -> In this video Depenetration is disabled.



    ** Sorry for the double post **
     
    BTStone likes this.
  10. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    Hey,

    Started experimenting with Kinetic2D, first impression is really good. It has more features than my quickly cobbled together solution and is definitely designed more modular. Taking a bit of time to match the 'feel' to my own solution, but generally it's going quite good.

    Some quick feedback:

    there could definitely be a bit more documentation,
    - e.g. jumping and blend trees, using an AirBlend parameter but no explanation what the values represent (first assumption was ranging from 0 to 1, but that's not the case, noticed in the debugger the values go from positive to negative over time.),
    - How to interpret Cancel Jump min/max time ( default = 0.1 and 0.2) but what exactly does it mean? Especially since the description says it's not related to time but to % of the max jump height... Can't the jump be cancelled anymore after the max-value (or before the minvalue)?

    Other thing I ran into is using "Super Tight" for the horizontal movement profile, but then the horizontal part of WallJump doesn't work. It more or less aborts immediately, probably due to the min/max-duration being zero). WallJump should probably have it's own duration-value.
     
    Last edited: Apr 20, 2020
  11. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    Question, I was looking into faking buoyancy. So assuming we have water at a certain level (character head can't go below water) but with the waterlevel moving slightly up and down.

    Now we can have a floor at such a position that its a hard limit keeping the head of the character above water, but when having the soft up/down movement of the waterlevel with CharacterController.Move passing in a y-value of the offset, it would only allow allows for the up-movement part of the wave (and not the entire down-movement).

    So we either need to ignore floor-collisions while in water (probably not a good idea), or offset the character a bit 'up' when falling in the water, so he's standing slightly above the floor ( to allow for the down-movement of the waves). Or maybe turn of gravity the moment he hits a spot slightly below the waterlevel... Or maybe there's a better way to do this, any suggestions what a good approach would be?

    Update: Figure out a solution, it's best to not mess with the physics with Move or anything, but directly influence the position of the graphical childobject :) Would be convenient if CharacterController2D would not only keep a reference to the characterAnimation, but also to the characterGraphics.
     
    Last edited: Apr 25, 2020
  12. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi @rboerdijk sorry i missed your post (Sunday). In general one of the main things i improved is the movement, for instance, in the next version you'll have "acceleration", affecting the character while input is detected (WASD), "deceleration", same but without input (No WASD), and a "speed limit". These concepts can be applied independently to stable, unstable and not grounded state. This way a wall jump in "Super tight" can be much more believable and expressive. The same goes for the sliding, which i removed that from the main component (CharacterMotor), and instead a put that into a the main state (NormalMovement state, which is the same as the Horizontal + Vertical movement abilities).


    To fake buoyancy you will need to add a custom ability, enable that under certain conditions (i don't know, normal state + a trigger (?)) and modify the velocity as you want. You can detect how much of the body is under water (Math + character body properties) then increase/decrease this "buoyancy velocity". There are a lot of ways to do this, in fact there is an entire presentation about this (not for a kinematic body, but the math should be useful).


    And yes the character now holds a reference to the graphics, although a lot of things have changed (last update was in september 2019).
     
  13. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    Thanks for the replies and the information.

    For clarification, I wanted super-fake (nothing remotely physically accurate) buoyancy. I already have water, know the 'normal' waterlevel and at every x how much above/below the wave is (delta-y). I was just having difficulties applying that delta-y to my character, until I realised I can bypass the CharacterController entirely and instead use the CharacterGraphics-position (which stores the initial child-offset) and add my delta on top of that, while the Controller is actually standing on the floor. Getting to the CharacterGraphics is easiest if the CharacterController stores it (nice the next version will have that!)... Works like a charm :)
     
    Last edited: Apr 26, 2020
    lightbug14 likes this.
  14. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    Hey there, me again.

    I finally got around to try out the higher level code ( behaviours, inputs for AI ) and want to customize it a bit. Since you mentioned 2.4.0 and 3.0 I was wondering how stable the interface (at least of the core) is going to be, especially for 3.0? I intend to leave the Core alone and customize in the \implementation part, but I'd like to avoid having to rewrite major parts in 2 months or so...
    Regards
     
  15. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    It's hard to say, because this 2.4.0 and 3.0.0 thing has been giving me nightmares in the past few months. I have both of these versions almost ready (especially 3.0.0 which is getting some of the good things from another asset of mine -> CCP ), the big difference is that 2.x.x relies heavily in autoSync and transform, something that to me belongs to the past (also Unity is clearly recommending to avoid this). Meanwhile, 3.0.0 it's like super stable at the moment. When i see back to 2.4.0 there are obvious things to improve, which i have already done in 3.0.0. So, even all i said about one version or the other, the most stable and modern version at the moment is 3.0.0.

    To give you a proper answer, regardless of the version you see on the store, the character interface is trying be similar in a lot of ways, you set its velocity (world), its localVelocity (local), even its rotation from outside.The interaction with the character will be almost the same, so don't worry (too much) about that.

    However, regarding the "CharacterActor" (the old "CharacterMotor"), there are a lot of good changes in version 3.0.0. For example, the slide movement is not controlled by this component anymore, instead the normalMovement state (from the implementation) is handling this. The same goes for the ground alignment, which it's a graphics feature. Kinematic platforms (a part of the core now) can push characters (without these characters using depenetration), each character is controlled by a "Scene Controller" which updates every character and platform in a specific order (Also you can manually re-simulate past frames over and over if yo want).

    Yeah, the core try to be same but there are some significant changes.

    The implementation is another world, very similar to the one in another asset of mine (Character Controller Pro). So, if you want to know how this new implementation will be, please check the CCP Documentation, there is a whole section about it.


    Regards.
     
    rboerdijk likes this.
  16. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    226
    version 3.0.0 seems promising for me, the only question is when can we get hands on it ? I'd rather sonner than later (even a preview version )

    also, how much effort would i expect to upgrade 2.x version to 3.x ? i heavly use 2.x's `implementation` as basis to achive my CC.
     
    rboerdijk likes this.
  17. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, in general version 3 is a major update, it improves a lot of things from 2.x.x (especially the implementation part). This new version contains most of the 2D things + implementation from my Character Controller Pro asset. It is the result of several months of work, including a lot of feedback, bugs reports, new tricks, new stuff i learned, suggestions, tests of all kind, etc. We are talking of 9 o 10 months of development, so the new version will be very diferent in almost all regards (IMO a far better asset). The structure (core+implementation+demo) + features (asset description page) will be there,so don't worry about that.

    I can't tell you if your particular project will be easy to upgrade or not, compatibility-wise version 3 is a b*tch. If you have an entire game built upon 2.x.x, don't upgrade right away, always play around with the new version, see if the new things are really relevant for your project.

    Also (very important as well), the 3.x.x cycle will be the last. No more major updates for this asset, from now on i will focus in feature updates and bug fixes.

    I understand the question about the ETA, everyone is asking me the same thing. What can i say? the new version will be there eventually. I don't give any more ETAs because i always ended up lying everytime (unintentionally, of course). However, I can answer any question related to the new version, maybe you want to know something about a specific feature, how hard will be to update X from 2.x.x to 3.x.x... things like that.
     
    samanabo and rboerdijk like this.
  18. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    226
    IMHO, preview version (like unity does) maybe a good starting point for a major release, you can distribute it among a few people to gather feedbacks quickly and effectively, i'm not in a rush, we all know how hard it is to ship something. so far, good job and pls continue :)
     
  19. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    Wanted to say not in a rush either, since 2.x is really great already and it's a great foundation to build upon.

    In the meanwhile added one-time playback of sequences (after which it switches back to human-control), added movement-profiles to the sequences to influence movement during a sequence, added an ability and got a few primitive enemies moving around by extending k2d... all working nicely.

    What I'd do hope to see in 3.x - besides good documentation - is a reference implementation beyond movement abilities (for e.g. attack and dying) and a bit more powerful sequence-system (beyond inputs and durations) where you can get a few hardcoded "events" to which you can react ( e.g. switch to ai-brain at time, switch to human when at t=end, change movementprofile at certain time) and possibly callbacks for custom events as a generalization (any chance that'll be in?).

    Anyway, just rambling, got the things I needed implemented in 2.x and can always extend 3.x myself ;)
     
  20. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    226
    can you share some details of "edge detector" (how to implement in current version?)
     
  21. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Unfortunately that feature was one of the many reasons i decided to create a new character controller (now a complete asset). That was possible only by using a capsule, due to the spherical nature of the ground check (whether you use a sphere/circlecast or a capsulecast). If you use a box to do this (like K2D does) the contact point you get is not reliable/predictable at all. For example:


    To know if the contact point belongs to an edge, you just need to get two more normals (see the image), and measure the angle between those vectors.


    If the measured angle is greater than X (a value), then the character is on an edge.
    -------------------------
    You can also use the "correlation between the normals", it's just a fancy way to determine the same, but in a complicated and not intuitive (at first) way.
    dot (n1,n2) = n1.magnitude * n2.magnitude * cos(n1,n2)

    ... For normals this is kinda useless, since n1.magnitude = n2.magnitude = 1. So you got the cos(n1,n2)

    And now you need to know that:
    90 degrees (n1 does not have anything in common with n2) ---> cos = 0
    0 degrees (n1 is identical to n2) ---> cos = 1

    So, an edge will be detected if the correlation is "lower than" a certain number.

    ---------------------------------
    If you use a box (K2D), you can still fire an array of rays (3 or more) and compare the results (hit or not) in order to determine if the character is on an edge or not. It is not the same result, however depending on the application this can be more than enough (for example, triggering a "close to the edge" animation). Although this is fine for a blocky level, this will not work at all with the example from the image above (too complex for this).
     
    filod likes this.
  22. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    226
    a bit confusing about Character Controller Pro, it supports 2d&3d, is it going to replace Kinematic 2D?
     
  23. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    226
    also a question about oneWayPlatforms, how can i achive something like PlatformEffector2D 's Rotational Offset /Surface Arc ?
     
  24. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    I guess the fundamental difference between Kinematic 2D and CCP is "Kinematic Rigidbodies (2D-only)" vs "Dynamic Rigidbodies (2D and 3D)". I doubt that will merge into one package... (?)

    Note that I own both, and I was wondering if it'd be worth experimenting with CCP as a replacement in my usecase (just to get a feel of how it would work, and how different it would be) but k2D is working fine, so I didn't see an urgent need to spend time trying this. Also I think CCP was missing some things I heavily rely on (walljump, wallslide) and since it's working in K2D I didn't feel like spending time re-implementing those :p
     
  25. qua1ity

    qua1ity

    Joined:
    Aug 17, 2014
    Posts:
    5
    Hi, I have a question. I'm trying to add a simple knock back effect on my player, for example when bumping into an enemy. Basically just by setting an AddVelocity(), which works fine. However when the data "Start duration" and or "Stop duration" in the horizontal movement profile is set to 0, this does not work. I assume It's because then in the HorizontalMovement script, the velocity just keeps getting set to 0.

    What is a good way to solve this? Do I need to make like a knockback state to stop the Process function in the HorizontalMovement script? Or is there a better/simpler way?
     
  26. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    226
    hmmm, how soon? really need these OneWay features right now...
     
  27. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Sorry everyone, i missed a bunch of questions. I'll try to answer them as quickly as possible.

    I have implemented those two (wallslide and walljump) in CCP (next update) ;)

    Unfortunately the state system used in K2D is based on abilities rather than states. What you're proposing is totally valid, you will need to create a new state and add the related ability to the character. Look at the existing abilies as examples, usually you'd need to add an if statement at the beginning (e.g if(state != Knockback) return;).

    The short answer is yes, after some thought i decided to create an upgrade from K2D to CCP.
    I will explain everything about this in much more detail in a few days. But yes, i'm happy with the decision, this seems like the way to go, it was inevitable at this point.
     
    filod and rboerdijk like this.
  28. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    Didn't want to flood you with questions instantly, but in the meanwhile (a little more then) "a few days" passed, and dozens of people (okay, at least one) are eagerly waiting for those details you mentioned :)

    So I'd like to understand what that upgrade entails:
    - Does that mean CCP and K2D will be "merged" into 1 package (K2D deprecated, 2D functionality added to CCP?), or
    - Does "code structure/improvements" from CCP will be used in K2D (but they remain independent)?
    - Will the new package contain 2D functionality for both Dynamic and RigidBody?... and if so, will we be able to easily switch between the two?
    - What about the 2.4 and 3.0 updates you mentioned earlier this year (will either of them ever be released? )
    - Any rough timeline on when the big update is going to be available?
     
  29. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    dozens? ... of thousands :D

    Normally i would say yes, although I'm not 100% sure about this (at least i won't do it right away). I mean, even is CCP is the natural evolution of what i intended with K2D, there are still one or two things you can do with K2D. I think i'll decide this after the upgrade, just to be sure.


    The next K2D (2.4.0) has improvements in general, a new way to depenetrate from moving platforms (without using "depenetration"), better performance, fixed time step + interpolation, a better slide algorithm, and more stuff (which i'll specify in the release notes)...in general it feels like a "better and smoother 2.3.1", not like a "reduced version of CCP". The state machine, the improved actions, the AI behaviours, the custom input handlers, the animation system, all these things from CCP will not be there :(. Unfortunately i can't do that now because that's already in CCP.


    2.4.0 it's working as expected :), i think everything is done (code and scenes). I'm doing API/Documentation stuff now.
     
  30. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Version 2.4.0 is now available!


    ... finally :D

    You can see all of the new things/changes/fixes/improvements (hopefully i didn't missed a lot) in the release notes.

    Warning:
    This is a special version (not a major update, but quite big for a simple feature update), there are a lot of changes. In fact, i had to leave a lot of things as they were, in order to mess as little as possible with compatibility. So, at the end of the day i'm quite happy with this version.

    ──────────────────────────────────────────────
    So, what now?
    As i say in the description of asset store page: "This (version 2.4.x) is the last feature update this asset is going to get". That means that i'll work in minor updates, bug fixes and small improvements. Nothing big is going to change in the future, whether is the animation component, the character brain, inputs, AI, etc. Those components/systems will remain as they are.

    As i mentioned before, Character Controller Pro (CCP) is the evolution of K2D. So, it's time to "merge this branch" once and for all.

    Will you deprecate the asset?
    Probably not, at least for now. I could change my mind, though. For instance, if most of K2D features become obsolete within a few years, in that case there would be no reason for me to keep maintaining/supporting this asset.

    Will CCP replace K2D?
    :rolleyes: well, something like that, let me explain. CCP is a new asset, originally i didn't want to make a better K2D clone, instead i wanted to make a character controller asset with (if possible) the core idea of K2D, but expanded for 3D as well.

    Is CCP "K2D-ready" now?
    It supports 2D :), yes, although i would recommend to wait for the upgrade:(, which i will create once i have (at least) the basic K2D features ready (most of them are ready now). Hopefully CCP 1.2.0 will be the one.

    Why CCP?:

    - Old vs Modern:

    CCP is much more "modern" than K2D. Everytime i go back to K2D it feels like an outdated asset, especially considering that CCP was created as a K2D update (almost a year ago). Since then, many problems were fixed and improved with CCP.
    CCP has a lot of nice features already implemented, such as better collision detection, a proper state machine implementation, the integration of the new input system (or any input system yuo want), a proper animation system (IK, root motion... playables are coming), an API reference, and much more. Trying to put all that back into K2D was a nightmare (imagine putting Unity 2020.1 features into Unity 5 o_O). So, instead of doing that, i'll do the opposite, bring K2D into CCP.

    - Kinematic vs Dynamic:
    This naturally creates the big question: How is that a Kinematic CC will be replaced with a Dynamic CC? Well, CCP does almost everything like a Kinematic CC (that's the "hybrid approach" i mention everytime).
    Also, 99% of the users don't care about the technicalities of a kinematic CC, they only think of movement and control, and that's totally fine (i would have done the same).

    - Control:
    You get the exact same control. CCP will not give you a floaty character (if that what worries you). The same concept of Velocity applies in CCP as well.

    - Documentation:
    Those who have K2D know that the docs are realy basic. The CCP documentation is being updated regularly, and it's much more detailed.

    - Multi-dimensional:
    CCP works with 2D and 3D, so your 2D logic should work just fine (and you'll get also a 3D character controller ;)).

    - Support:
    Another big topic... for every one question i get about K2D i get 20 more about CCP. So, i'm more quick and efficient in the CCP world (which is understandable, K2D previous update was in Sep' 2019). This is better for me, and for you as well.


    I will update this thread with more details once CCP 1.2.0 get released.
     
    PanupunJJ, rboerdijk and filod like this.
  31. maltakereuz

    maltakereuz

    Joined:
    Mar 29, 2015
    Posts:
    54
    Hi, i have a little bit strange behavior on pause: Game freezes with exceptions like this:

    Code (CSharp):
    1. [Error] transform.position assign attempt for 'Husky' is not valid. Input position is { NaN, NaN, NaN }.
    2. MotionCustomBehaviour.MoveRigidbody() at /Lib/Kinematic2D/Core/Scripts/MotionCustomBehaviour.cs:58
    3. CharacterMotor.Move() at /Lib/Kinematic2D/Core/Scripts/CharacterMotor.cs:873
    4. CharacterMotor.UpdateBehaviour() at /Lib/Kinematic2D/Core/Scripts/CharacterMotor.cs:838
    5. CharacterController2D.UpdateBehaviour() at /Lib/Kinematic2D/Implementation/Scripts/CharacterController2D.cs:114
    6. UpdateCustomBehaviour.Update() at /Lib/Kinematic2D/Core/Scripts/UpdateCustomBehaviour.cs:38
    I grepped the source, but can not really find any file with version, but i have purchased Kinematic2D in january 2020, so it should be 2.3.1 i assume.

    I can not really understand why FPS dropped to zero, it is even hard to stop the editor from playmode. If it was only NaN-transform, it should just give some errors, without dropping FPS. Is it all just div by zero problem?

    upd: I looked for a new version 2.4.1 and only FixedUpdate is available now. Was this pause behavior the reason for that? (i would like to stay in my version for now, if it is possible). I have foreboding that moving all enemies in my game to FixedUpdate will solve the problem, but it is pretty big change (i have fear to brake something). So i would like to really understand what happens first.


    upd: just adding
    if (Time.paused) return;
    to RootUpdate of Character solved the problem.
     
    Last edited: Dec 10, 2020
  32. SimplyNew

    SimplyNew

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

    I am using K2d in a 2d side scroller and using Unity's SpriteShape heavily for level design. So, basically my levels are uneven and contains all kind of possible shapes, even a loop (like sonic). For static shapes, everything works fine. However, I have one issue where if spriteshape(with edge collider) is scaled (up/down) at run time, sometimes collission's are not detected correctly and character falls off. I have tried migrating to newer version as well, but it didn't help either, even using Kinematic Platform. Can you please help me with this? I have also tried with spriteshape and polygon collider.

    I see you have release CCP 1.2. If CCP can handle such scenarios, I am open to go for that. One more question: If I decide to migrate to CCP, how much effort do you see? I have 3-4 custom abilities developed and few features that I added on top of K2d (like Coyote jump, Unity's latest input, Few changes in wall slide, wall jump). Just need rough estimate, I have fair to good understanding of K2d.

    Thanks
     
    Last edited: Dec 30, 2020
  33. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, sorry i missed your post! :oops:

    I don't really know what is happening there, Do you have the script that is modifying "husky" (i assume that's an object).

    Makes sense. You are right, now FixedUpdate is the only update method, like it should have been from the start. If you use fixed update + interpolation movement you'll notice that the character does not move perfectly in sync with the platform. This was fixed with the SceneController introduced in 2.4.0. Also a ton of new improvements were introduced, i'll highly recommend that version if possible. However, i understand your POV, what if after changing everything this issue is still there.

    Ohhh, sorry, i didn't read that before! i'm still not sure about what's happening.

    Hi there.
    Well, that's expected because the character supports what i call "moving/rotating platforms". This means that the character measures the displacement and rotation in order to move/rotate with the ground (it doesn't take into account the scale... for now). Scaling the ground can be too much for the character to handle (and apparently it is). In any case, see if using depenetration fixes the issue.

    I'll have to test that situation for myself in order to confirm you this. However, CCP uses a dynamic rigidbody, so the character will never fall through the platform. Maybe it won't be super precise while moving/rotating (this is something i need to test first).

    Well, CCP includes:
    - coyote time (i call it post-grounded time) and pre-grounded time (a.k.a "the character is in the air, you hit the jump button before hitting the ground, the jump action will be executed when the character is grounded again")
    - 2D/3D wall slide + wall climb (with wall jump available).
    - custom input handler, you can easily implement your own input solution (this is the one with the new input system).

    One very important thing you need to consider is that CCP uses a finite state machine. On the other hand K2D uses an ability system (based on enums, the "states").

    Moving, jumping, sliding, all those abilities have been improved and modified, so don't expect a 1-to-1 relation between K2D abilities and CCP states.
    For example, this is the NormalMovement state (the main locomotion state) inspector (planar movement and vertical movement):
    upload_2020-12-30_3-31-28.png

    As you can see the state contains everything inside, there is no adding/removing stuff on the fly (e.g. removing "VerticalMovement", or maybe adding "JetPack"). From the code perspective this is really easy to work with, however maybe this is not that exciting from a designer perspective.


    Needless to say that both character controllers (CharacterMotor in K2D, CharacterActor in CCP) are completely different in nature, they do behave and present the info in different ways.
    For instance, CCP does not support one way platforms ATM (the official version doesn't, i have this working).


    So, How much effort? Unfortunately i can't tell you an exact number or something, sorry :(. There will be a learning curve, no doubt. Since CCP comes with some good abilities included, i'd probably say it won't be as hard as making everything from zero (K2D -> CCP). Probably the worst part will be learning a new asset, making your own abilities, learning about actions (similar to K2D actions), etc. If you decide to read the documentation i believe in one week (or even less) you'll be able to understand the basics of the asset.

    Hope it helps.
     
  34. SimplyNew

    SimplyNew

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

    Thanks for detailed response. For my project, character stability on Ground/platform is the most important, specially on scaling, rotating, moving platforms. Using K2d, it falls off and it's a very bad gaming experience. I also tried with depenetration. It didn't help either.

    Since you said in CCP, character will never fall off, that's encouraging. it's ok, if movement in that case is not accurate initially. It can be worked out/fixed/implemented.

    I started looking into the CCP documentation. It indeed different than K2d in many ways. One initial concern I have is animation/animator. Looks like CCP is very tightly coupled with Unity's animator. I am using Spine for animation and don't use animator at all and don't intend to because of few limitation on Unity animator. Is my understanding of tight coupling with Unity animator correct? In K2d, I didn't have to do much to use Spine animation. Can you please guide what all steps I need to take to completely use different animation system?

    Thanks.
     
  35. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi, CCP's implemention uses the Animator component, however this is not a requirement at all. If the state machine doesn't find this component then everything (from the logic perspective) will still work. In K2D, animation was handled from the outside by using a dedicated CharacterAnimation component. This is not ideal, sometimes you want to trigger something based on the state/ability internal logic, that's why by deafult CCP's states know about the animator and all the Animator-based messages.

    Yeah, one thing to consider is the colliders dimensions. Now we are dealing with physics, so if the scale difference (currentFrame - previousFrame) is big enough (and the platform collider is really thin, for example an edge) it might cause some trouble (the character will depentrating in the wrong direction).
    Like i said, i will do some test, it seems like a really cool "feature" to introduce (K2D and CCP).
     
  36. SimplyNew

    SimplyNew

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

    Thanks for info. I purchased CCP and was able to integrate in my project. Few of the observations/queries:

    1. Most important issue that I had about character falling through platform is resolved. Believe me, its very weird platform. It's a spriteshape and I am animating all spline points which scales up and down the shape, also changes the shape of the platform. In addition to that entire spriteshape goes up and down. CCP handled it very well till now.
    2. In CCP, when character is in air there is no control. In K2D, it had very good control and character movement was very agile. Is there something that can give air control on jump? I played with ccp gravity, mass, jump height,jump time. But was not able to do this.
    3. Since, I am using Spriteshape, the platforms are curvy, meaning there is no hard edge. So, if you visualize steps where there is no sharp step, but with curvy steps. In that case, character bounces off when it touches it. It's very weird and sometimes it kicks in slide. May be it is considering step as wall?
    4. One feedback about overall experience while migrating: K2D had good abilities, motor and graphics separation, but CCP is bit of monolithic. This is my initial observation. I might be wrong. May be I am used to k2d architecture and was very comfortable with it. :)

    Please, provide some guidance about point 2 and 3.

    Thanks
     
  37. SimplyNew

    SimplyNew

    Joined:
    Jul 21, 2020
    Posts:
    9
    Update:

    After further digging, I was able to resolve issues 2 and 3 myself. I am moving my further questions to CCP thread. I think it can help others as well.

    Thanks
     
  38. Mercbaker

    Mercbaker

    Joined:
    Apr 18, 2017
    Posts:
    18
    Can anyone steer me in the right direction to implementing a top-down approach using K2D?
     
  39. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi,

    I was writing some code (top down character) for you when i discovered two or three silly (but important) bugs. So, i'll upload an update (tomorrow maybe) bringing some fixes + QOL improvements (inputs, character actions, AI) + TopDown movement ability.

    A top down character can be implemented by:
    1. Using the "always not grounded" property.
    This property works in 2D (X and Y), however there is no depth involved (Z), so don't worry about the grounded elements. The body shape effectively used by the character will be the entire box.

    2.Moving the character using the XY plane = XY inputs, basically W/S means up/down, A/D means left/right.
    The "HorizontalMovement" ability works just fine with this:
    Code (CSharp):
    1. characterController2D.SetVelocityX( speed );
    ... however "VerticalMovement" consist of gravity + jump (not suitable for a top down game). One thing you can do is extending/customizing (a.k.a create your own version of) the HorizontalMovement ability and simply call it "TopDownMovement" or something like that. At this point you can ignore Horizontal and Vertical movement.
    The only difference is that this ability forces the "always not grounded" flag to true, and sets a vector 2 as the target velocity (X and Y).
    This is the movement code:

    Code (CSharp):
    1.  
    2.    protected virtual void ProcessMovement( float dt )
    3.     {    
    4.         Vector2 targetVelocity = Vector2.zero;
    5.    
    6.         if( characterBrain.CharacterActions.right )
    7.             targetVelocity.x = movementData.baseSpeed;
    8.         else if( characterBrain.CharacterActions.left )
    9.             targetVelocity.x = - movementData.baseSpeed;
    10.  
    11.         if( characterBrain.CharacterActions.up )
    12.             targetVelocity.y = movementData.baseSpeed;
    13.         else if( characterBrain.CharacterActions.down )
    14.             targetVelocity.y = - movementData.baseSpeed;
    15.        
    16.  
    17.         Vector2 currentVelocity = Vector2.SmoothDamp(
    18.             characterController2D.Velocity ,
    19.             targetVelocity ,
    20.             ref velocitySmoothDamp ,
    21.             targetVelocity != Vector2.zero ? movementData.notGroundedStartDuration : movementData.notGroundedStopDuration
    22.         );
    23.    
    24.         characterController2D.SetVelocity( currentVelocity );
    25.     }
    26.  

    Sorry for all the up/down/left/right hard-coded behaviour, this will be improved for the next update. I'm using this:
    Code (CSharp):
    1.    protected virtual void ProcessMovement( float dt )
    2.     {    
    3.         Vector2 targetVelocity = characterBrain.CharacterActions.movement * movementData.baseSpeed;
    4.          
    5.         Vector2 currentVelocity = Vector2.SmoothDamp(
    6.             characterController2D.Velocity ,
    7.             targetVelocity ,
    8.             ref velocitySmoothDamp ,
    9.             targetVelocity != Vector2.zero ? movementData.notGroundedStartDuration : movementData.notGroundedStopDuration
    10.         );
    11.      
    12.         characterController2D.SetVelocity( currentVelocity );
    13.     }
     
    Last edited: Feb 13, 2021
  40. FelipeQuevici

    FelipeQuevici

    Joined:
    Jan 8, 2013
    Posts:
    13
    Hello Lightbulb, I've been using your asset on my game, and there are a few issues I had, which I want to know if the CCP solves, also related to the question, we who bought this asset will have some kind of access to CCP?

    My issues (with 2.3 I guess, I bought in May and just now realized I could update, not sure if 2.4 solve my issues):

    - External Forces: I have a treadmill that moves the character, also a fan that pushes the character up, I needed to make a method to add external forces and process these forces (the fan force gets lower the further away you are from the fan). It works mostly fine, and I like my solution, but it's a little convoluted.

    -Inertia: If I jump from a moving platform I want inertia (my external forces implementation kinda solve that, but it feels hacky)

    - Pushing objects: How can my player push other objects? If I try to push a Dynamic Rigidbody the forces don't seem realistic, and I actually want to Push platforms (say a block) that have their own physics behavior, so I can't use a dynamic rigid body.

    - Dynamic Grounds on Dynamic Grouds: I want to have Platforms on top of Platforms, that work with dynamic ground, say if a falling block falls in an elevator, I want the block to be dynamic grounded to the elevator. I implemented both as a custom CharacterMotor implementation. However, that did not work because the raycast object was on the Dynamic ground layer and if cast to itself sometimes to check if it was grounded. I made the raycast ignore the object which was casting. Still a lot of weird interactions happened (and also they can't push each other, so a falling block my stick to a descending elevator, but the elevator can't push it up so it can't move up it just gets stuck)

    I know some of these problems are not really what this asset tries to solve, and maybe my approach of using a dynamic character for every platform is fundamentally wrong (the 2.4 update seems to have a new way to do that with a universal controller for characters and platforms), but I still want to know what you think about those issues because, in the end, all my physics system has to be aligned, and committing to your asset is basically committing to your physics system.

    I don't really mind if I just use your core engine and have to redo all the implementation for my game (I already did that) and if I have to change some of your code (also did that haha) I just want to have a neat character controller (i can with your asset) fully integrated to a world with a lot of dynamic objects (couldn't do it yet)
     
  41. lightbug14

    lightbug14

    Joined:
    Feb 3, 2018
    Posts:
    447
    Hi Felipe,

    Sorry for the delay!

    Yes, i want to make an upgrade soon (like really soon, probably this week/month). I mentioned this a few months ago, don't expect a 1 to 1 conversion between K2D and CCP. K2D handles one way platforms really well. CCP also handles OWP, but not as well as K2D (if you want static/slow platforms then fine). Regarding the rest of the features, CCP is clearly better.

    In general, making a kinematic CC react to dynamic rigidbodies as intended requires two things:
    1. You need to know the math behind every type of interaction, which in some cases might be impossible to get right (this is why the physics simulation is really good at this)
    2. Unity must let you solve the collision before the simulation (in box2D this is known as "PreSolve"). For example, it is impossible for me to know when a contact happened (CC pushes a RB, or maybe a RB pushes a CC) prior to that event. Unity just solves everything and gives me an OnCollisionEnter/Stay. So, it is impossible for me to produce perfect results.

    Item 2 is why you can immediately detect if a CC is kinematic, you push something and that thing is being push really hard (an infinite mass character vs a finite mass rigidbody).

    In this case, CCP solves this naturally, not hacks.


    The concept of being fully grounded to something, especially in video games, is normally just a clever lie. Probably this could naturally work if the dynamic block is kinda heavy, has some minumum drag, a material with some friction, and so on. If you want to simulate this stuff then you are getting farter away from the vanilla physics system (being less and less compatible with the rest). K2D's Character is completely outside of the system, the same goes to kinematic platforms, but that's ok i guess.

    One thing you can do in order to simulate this is:
    1. Set the platform movement in such a way that you never move the object before the simulation (use velocity, MovePosition, Force, whatever). Avoid changing position directly.
    2. Detect using contacts if something is on top of the platform and save those contacts (per object)
    3. After the simulation -- the platform has moved, calculate where all those contacts should be (e.g. Obj A was at <1,0,0> but now needs to be at <1.5,0,0>.
    4. Move the object associated with the contact to the target position (using interpolation if possible, very important).

    Regarding interpolation, this is impossible to do in 2D (perfectly), you can actually do it in 3D due to a bug o_O. For CCP i implemented my own interpolation, i should have done that a long time ago.

    It depends on the "fully integrated". If you mean supporting all vanilla rigidbodies, then i agree, that is the intended way of doing this. For CCP i did this, no matter what type of body we are talking about, if it moves (like i said before, by letting the simulation to do that) then the character react to it perfectly. Why don't implement this for K2D (i could do it)? The time i need to spend doing this will be a lot, it is far more easy for me to offer the upgrade.
     
  42. FelipeQuevici

    FelipeQuevici

    Joined:
    Jan 8, 2013
    Posts:
    13
    Thanks for the answer, btw I love your system, simple to use and really effective, my game is just at a point where if I want to go further then I have to do a lot of stuff. I haven't changed more stuff yet because there is a lot on the to-do list before I add these features.
    It seems like CCP will solve some of that, and some I will have to work on my own, that is totally okay, I will take a look at that new update with CCP. Thanks again, and good luck with the development!
     
    lightbug14 likes this.
  43. Hasan_Green

    Hasan_Green

    Joined:
    Oct 15, 2020
    Posts:
    2
    Kinematic character in Dynamic Obstacle objects slope bandicam GIF 1.gif

    after I solved the problem
    trigger.jpg
    bandicam gif 2.gif
     
    lightbug14 likes this.
  44. NotEvenTrying

    NotEvenTrying

    Joined:
    May 17, 2017
    Posts:
    43
    Hi @lightbug14 , I've recently been refactoring my own custom controller for a 2d platformer game, and have been looking for an asset to use as a reference/guide as I remake my own - I was wondering if K2D or CCP would be a better pick assuming that I don't need any of the extra features/abilities, and am mostly looking for a solid low-level base for collisions/movement that is also very performant (I will have large numbers of characters, potentially a few thousand, at the same time). From what I can see so far, K2D definitely seems like the better one for my use case, but wanted to get your thoughts, just to make sure :)
     
  45. gxchris

    gxchris

    Joined:
    Nov 28, 2020
    Posts:
    3
    Hi @lightbug14 , I am using the new input system and wonder if you can upgrade the package to support the new system? if you can provide some guidance, I can change it myself. Thanks