Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[RELEASED] Easy Character Movement 2

Discussion in 'Assets and Asset Store' started by Krull, May 5, 2021.

  1. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi Mike,

    Thanks :)

    About your question:

    You can re-use the included ladder example code.

    A Character is the base class of all the other character-based, like FirstPersonCharacter, ThirdPersonCharacter, AgentCharacter, etc. So all the code is compatible.

    In your case you have two options:

    As you can see exploring the ThirdPersonCharacter source code, it extends a Character class adding typical third person control, so you can copy the ladder example code to your custom third person character.

    Another option is use the ladder example character as your base character, and add third person controls to it.

    Either way should work.
     
    moshecristel likes this.
  2. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi Mookfasa,

    I am afraid this is not easy to do without a major core code re-implementation. In short this would require an almost entire rewrite of the CharacterMovement component.

    You can use the CharacterMovement MovementSweepTest function to 'look-ahead', this is the same function used internally to perform the continuous collision detection. Additionally you can use the CharacterMovement FindGround and ComputeGroundDistance, to sample any given position is walkable or not.

    Another approach is use additional(s) collider(s) / trigger(s), and while it won't automatically stop alter the character's movement, you can make use of the OnCollisionXXX / OnTriggerXXX methods to modify the characters velocity accordly.
     
  3. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    [RELEASED]

    Easy Character Movement 2

    ----------------------------------------

    VERSION 1.3.0

    - Removed dependency on new Input System. ECM2 includes 2 versions, ECM2 - Input System, using the Unity's new Input System package, and a new one ECM2 - Input Manager, which uses the old input manager without any dependency on new input system. Users decide which version to import.

    - Refactored the package folder structure. This makes easier to work with package and prevent user confusion.

    - The CharacterMovement package has been removed from ECM2 package as this caused confusion to users.

    - ECM2 users now can download the CharcterMovement package directly from store!

    - Improved root motion support. RootMotion controller now accumulate and consume deltas.

    - Added new TeleportPosition and TeleportRotation to ease character teleportation. Teleport example has been updated and simplified.

    - Update Cinemachine third person example to add cursor lock / unlock management.

    - Minor bug fixes and improvements.
     
    my_little_kafka likes this.
  4. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    70
    Yay, new version. I can't download the Character Movement Package as yet, but I assume this is a store delay?
     
  5. TheMK-_-

    TheMK-_-

    Joined:
    Feb 8, 2018
    Posts:
    13

    OK that's great thank you, I will try extending from the example one first. If say I wanted to extend another example at the same time like fly or dash would this method still work or would copying be easier?

    Thanks again though, appreciate the support.

    Mike C
     
  6. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi,

    Thanks for letting me know. I'll wait till tomorrow, if not, I'll update the ECM2 package to include the CharacterMovement package as well.
     
  7. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Yes, it would work too. In the end your custom character will contain all the relevant code to perform its desired actions as your game needs.

    Regards,
    Krull
     
  8. my_little_kafka

    my_little_kafka

    Joined:
    Feb 6, 2014
    Posts:
    87
    Right, this kinda confuses me now. Right now I'm using Easy Character Movement 2, version 1.2.0
    I have the Character Movement folder, with a separate Docs folder, that, indeed, confusingly make me think it's from older version, but if I delete the folder, I recieve a lot of errors, like the ECM2 and this folder are actually connected. Did I messed things up (I'm editing the base source files to fit into my framework), or were these folder actually connected in the old versions and you decoupled them for this version? Everything so far works very good on the old version.
    Feels like the CharacterMovement component is being used by both systems?

    What does accumulating and consuming deltas mean? So far I'm replicating motion from the animations I made in Blender and it works very good.

    Thanks for the update, I'm glad you're keeping the package fresh, the best physics system for Unity I used by far.
     
  9. TheMK-_-

    TheMK-_-

    Joined:
    Feb 8, 2018
    Posts:
    13
    Hi Krull,

    I have another query as to possible functionality with the controller. Would it be possible to have additional colliders on the player say when they are carrying large objects like a crate etc? Was just prototyping a pickup object system and noticed the carried items will go through walls when standing close.

    I currently am just using a simple parenting system that sets kinematic and no gravity on the picked up item, though not sure if that is the best way to go about it.

    Many thanks if you have any insight on this and thanks for the latest update, just saw that today. Your doing great work.
     
    Krull likes this.
  10. Rin-Dev

    Rin-Dev

    Joined:
    Jun 24, 2014
    Posts:
    561
    Personally, I would probably follow a tutorial like this one by speed tutor. I feel like in the long run it would better benefit a pick up system.

    The way you're doing it is fine for prototyping quickly but to fix issues like that you'll need something a bit more robust.
     
    Krull likes this.
  11. TheMK-_-

    TheMK-_-

    Joined:
    Feb 8, 2018
    Posts:
    13

    OK cheers I'll check that out, I had looked at a few tutorials and most of them were the way I was doing it so I assumed it was fairly common approach.

    Thanks Again.
     
    Rin-Dev likes this.
  12. RogDolos

    RogDolos

    Joined:
    Oct 16, 2012
    Posts:
    42
    This is confusing. I'm not able to get it either, or I'm just not sure how I'm supposed to get it separately? I own ECM2 but just use the CharacterMovement bits.
     
    Broudy001 likes this.
  13. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    70
    I'm the same presently, thought it might be like others where it shows up as free if you have the ECM2 asset.
     
  14. TheMK-_-

    TheMK-_-

    Joined:
    Feb 8, 2018
    Posts:
    13
    Hi Rin thanks for the heads up on that video, I had a brief look and that is indeed similar to one of the methods I considered looks promising, similar to Skyrims. But originally I was wondering if multiple box colliders could get a result similar to this.

    (GKC demo if anyone's curious)

    But I'll do some more research into it and see if Krull or anyone else here has some insight.

    Thanks again anyway Rin-Dev all the best. ✌
     
    Rin-Dev likes this.
  15. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi @my_little_kafka,

    Yes, that's one of the main reasons I decided to remove the CharacterMovement folder from the Easy Character Movement 2 folder, and refactored the folder structure, it was confusing to find two docs folders, two example folders etc.

    In the new version, you only need to import the Easy Character Movement 2 - Input System package or the Easy Character Movement 2 - Input Manager which use the old input manager without any external dependencies.

    The CharacterMovement component is included in the source folder but without any examples, docs, to prevent confusion as indeed it is used by the Character classes.

    Due to this folder restructuration, I suggest you to completely remove the Easy Character Movement 2 folder before importing the new version.


    While the previous RootMotionController worked, in some cases, most noticeable at lower frames and where root motion displacement is large (for example during long dashings or jump attacks, etc) the calculated velocity was 'missing' some frames of information as the character is updated at fixed frequency and the animator (update normal) not, this lead to some desync causing the character to move less and most noticeable rotate less compared to the authored root motion animation.

    Worth noting for regular walk, run root motion based animations this is mostly imperceptible, but for rotations and large displacements it definitely affects.

    The fix accumulates delta positions and delta rotations while animation is playing (higher frequency than fixed step), later when is time to update the character, the character 'consumes' this accumulated deltas (calculate new velocity / rotation, and reset accumulated values), keeping root motion movement and rotation perfectly in sync.

    Thank you for your kind words =D
     
    my_little_kafka and RogDolos like this.
  16. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi @RogDolos and @Broudy001 ,

    Sorry for the confusion with this update.

    Easy Character Movement 2 aka the Character based clases, uses the CharacterMovement component as its character controller pretty much like the built-in cc; actually this CharacterMovement component has been developed as a direct replacement of the Unity built-in CC.

    This wont change, it still uses the CharacterMovement component and always will. What was removed and was causing confusion for users was including all the CharacterMovement package (sold separately and is free for Easy Character Movement 2 users) with its docs, demos, folders, assets, etc.

    In new version, as commented above, you simply decide to import the old input manager version OR the new input system version.

    In close:

    - ECM2 is now being distributed as two versions, one using the new Input System and another one without any external dependencies using the old Input Manager.

    - The Character Movement (asset store version) is now included as a separate package. This is aimed at developers who prefer to build their own movement mechanics on top of it without using any ECM2 features.


    Installation

    To install, simply import the desired package. For example:

    - To import the ECM2 input manager version (aka old input), double click on the "ECM2 - Input Manager (aka Old input)" file.

    - To import the ECM2 input system version (aka new input), double click on the "ECM2 - Input System (aka New input)" file.

    - To import the CharacterMovement package (asset store version), double click on the "Character Movement v1.0.7" file.

    IMPORTANT NOTE:

    You should not install the Character Movement package if you intend to use ECM2 as this is already included with ECM2 versions.

    Hope this helps to clarify the update,
    Oscar
     
    RogDolos likes this.
  17. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727

    I think the @Rin-Dev suggested approach is really good as you keep complete separation between character movement code and your pickup system. However as ECM2 is a kinematic character controller (meaning we have full control over it), it is not moved by other colliders, unless we explicitly code it (that's how kinematic character controllers works).

    An approach could check your picked up collisions (i.e: OnCollisionEnter, OnCollisionStay, etc) and use the collision data to alter the character's velocity accordly, for example completely stopping your character, slide along the plane collision plane, push the character, etc.

    Having said that I will perform some tests this weekend (limited time due work) and see if I could add a working example of additional colliders.
     
    TheMK-_- likes this.
  18. RogDolos

    RogDolos

    Joined:
    Oct 16, 2012
    Posts:
    42
    Thanks very much for sorting this out! I've got the new update. You're awesome, as usual. =)
     
  19. TheMK-_-

    TheMK-_-

    Joined:
    Feb 8, 2018
    Posts:
    13
    Oh that's fab thank you,

    I was just curious as how an approach to that might be accomplished, but if you think you could add an example I'm sure I'm not the only user who would find it useful. No rush though and thanks anyway for all your help.
     
    Krull likes this.
  20. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    That's great, glad I was able to help!
     
    RogDolos likes this.
  21. Redellion

    Redellion

    Joined:
    Feb 13, 2014
    Posts:
    2
    Hey Krull, any plans to start Discord so we can build a community around your awesome work?
     
  22. dmarqs

    dmarqs

    Joined:
    Oct 16, 2013
    Posts:
    41
    Hi @Krull ,

    I'm trying to run ECM2 at Unity 2022.2.2f1 and 2022.2.3f1 (both silicon) and I'm getting this issue:



    I don't think that's the correct behavior because that's not what is shown in the videos at the asset store. I tried both the current version from yesterday and the previous one. That's the demo scene that came with the game. I tried both of them, looks like it is something with the Character MonoBehaviour, I believe.

    Please, let me know if I'm doing something wrong and how can I fix it. Thanks! =)
     
    TheMK-_- likes this.
  23. TheMK-_-

    TheMK-_-

    Joined:
    Feb 8, 2018
    Posts:
    13

    This is because the collider is a capsule, if you set it to use flat base in the inspector and reduce the size of the collider it should fall off sooner, I believe.
     
    Krull likes this.
  24. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Thanks! actually working on it, so hopefully pretty soon :)
     
  25. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi,

    Yes, as @TheMK-_- already commented, that's normal behaviour for a capsule based character controller.

    You can modify it in two different ways:

    One is using the CharacterMovement perch offset property. This lets you define the character's 'feet' radius, acting as if the capsule's lower sphere is thinner so it will fall sooner.

    Worth noting you should not set it to zero, as you will be reducing the volume to a 'ray cast'. A good starting value is about 70% of your capsule radius.

    Another way is using the flat base option, If enabled, it performs ground checks as if the character is using a shape with a flat base. This avoids the situation where characters slowly lower off the side of a ledge (as their capsule 'balances' on the edge).
     
    TheMK-_- likes this.
  26. TheMK-_-

    TheMK-_-

    Joined:
    Feb 8, 2018
    Posts:
    13
    Hi @Krull I managed to get the ladders working on the third person so thanks for that.



    I just copied the code over in the end, the only thing of note for anyone else trying this is I changed the namespace in the ladder script to just EasyCharacterMovement, and unity is unhappy about the script being anywhere other than the characters folder so I moved it there.

    Weirdly the ladders example scene still works with the script elsewhere, yet my own scene with the third-person character requires it in the same folder or else you get a "The type or namespace name 'Ladder' could not be found (are you missing a using directive or an assembly reference?)". As to why I don't have a clue but it does work so +1 to krull.

    Thanks
     
    Krull likes this.
  27. TheMK-_-

    TheMK-_-

    Joined:
    Feb 8, 2018
    Posts:
    13
    Hi @Krull again.

    I wanted to share an update on my carry object system and for anyone else interested.

    I managed to get somewhat of a desirable result for the time being. I'm using a raycast from the players facing direction, and setting the walk speed to zero when within certain distance of an object. I also added a push-back force if the object starts to clip too far into the wall.



    and flow-canvas graph:
    Graph_character_carry-1PNG.PNG

    I will continue to experiment and look into improvements, such as stopping turning etc, and if anyone else has any ideas, or improvements feel free to share.

    Many Thanks.
     
    Krull likes this.
  28. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    290
    *edit - disregard - found it.

    After the new update, I cannot find the .pdf doc that discuss the individual examples. Where is the file located in the new folder structure?
     
    Krull likes this.
  29. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    290
    Noticed your demo 2 scene has a bunch of yellow messages and missing scripts on the latest update. The platform scripts and bouncers are missing.
     
  30. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi @The MK-_-

    Thanks for sharing your solution! As it should help others with your same problem.

    Your approach is correct, as basically you are performing an implementation of continuous collision detection, where you look ahead and check if the character is able to move to its desired destination.

    As previously mentioned, I did some tests regarding this case, from using the previously discussed use of OnXXX collison events to something pretty similar to your current solution, and found the later definitely is the most robust solution, and actually, similar to what the system internally does (Collide and Slide algorithm).

    Having said that, I plan to perform further tests and explore the possibility (very probably) to add the option to include additional collider(s) to define the character's collision volume, this will help in situations like this, and also in cases (like animals) where the capsule is not enough to enclose the desired volume in a future update. BIG DISCLAIMER here, this is based on initial tests (one additional collider) which works pretty well but obviously needs more general case tests and polish before it could be added to the store package.

    upload_2023-1-30_20-42-39.png

    Here the sphere is an extra sphere collider (trigger marked) added to the character as a child collider.

    Worth note this is a typical 'issue' with kinematic controllers, as a kinematic controller (in general) needs to manually perform its overlap / collision detection and response functions for any of its used colliders, something not so easy to do.
    An additional option I suggest you, is to do an overlap test and recovery (if needed) as this solves the rotation issues since the carried (other collider) is rotating around the character. Basically you do an overlap test for your carried item volume, then for each of its found overlapped colliders, you use the Physics.ComputePenetration function to resolve the overlap (move the character away).
     
    TheMK-_- likes this.
  31. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi @giraffe1,

    Mmm, I got no issues with demo scenes or missing scripts. Please make sure to completely delete all the previous ECM2 folders before importing the new one, otherwise this could cause some issues due the folder refactor.

    If your issues persist, what version are you using? (input system, no input system, etc. and your unity version).

    Thanks!
     
  32. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    290
    latest unity 2021 lts, imported your asset then imported the new input system package.

    I found the problem. I did not import the example folder.
     
    Krull likes this.
  33. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    290
    I have a question. I am using ECM2 with your new input system setup. I am extending the first person template. I modified your character setup from your default:

    First Person Character
    ->Root
    -->Eye
    -----> Camera

    to:

    First Person Character
    ->Root
    --->Eye
    -----> Primary Lean Pivot
    --------->Secondary Lean Pivot
    -----------> Camera

    I am going to add local z-rotation to the primary and secondary lean pivots. Where would you suggest is the best place to add my lean logic, based on your setup? If it matters, I will also be adding some floating arms with animations later on.

    Code (CSharp):
    1. using EasyCharacterMovement;
    2. using System;
    3.  
    4. namespace EasyCharacterMovement.Templates.FistPersonTemplate
    5. {
    6.     public class MyCharacter : FirstPersonCharacter
    7.     {
    8.         // Called in Simulate(float deltaTime) which is called in OnLateFixedUpdate()
    9.         protected override void Move()
    10.         {
    11.             base.Move();
    12.         }
    13.  
    14.         // Camera input is handled in here
    15.         protected override void OnUpdate()
    16.         {
    17.             base.OnUpdate();
    18.         }
    19.  
    20.         protected override void OnLateUpdate()
    21.         {
    22.             base.LateUpdate();
    23.         }
    24.     }
    25. }
     
  34. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    70
    Hi @Krull

    I was thinking of adding a ledge hang mechanic, but wanted to support it on moving platforms. I was considering just raycasting forward and moving to the hit point every frame when hanging, but thought I'd check if there was a transparent way like the existing platforms.
     
  35. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi @giraffe1,

    Typically for all camera related movement and animations I suggest using the LateUpdate method, as when this is called all is in its current state.

    Additionally, if you are not making use of the procedurally crouch animation, you can omit the base.LateUpdate() call, as all it does is call the AnimateEye method.
     
    giraffe1 likes this.
  36. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi @Broudy001,

    Mmm, for this to work you should use the CharacterMovement SetPlatform method otherwise the character won't register the platform, as this detects it during its grounding tests so it requires the character be on the platform.

    Your approach should work, detect the platform to hang (ie. a raycast, etc.) and once detected and your character should hang, assign the platform using the SetPlatform method commented above.
     
  37. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    70
    Oh that's awesome I'll give it a go, didn't see that method.
     
  38. MetalDonut

    MetalDonut

    Joined:
    Feb 7, 2016
    Posts:
    127
    I've been trying to get this to work with Fishnet but the characters don't sync properly (massive stutter/lag). The tutorials/examples seem to work where the move components are on the main parent game object which isn't how EMC2 is setup. @Krull I saw that you're looking at providing an example with Fishnet. Is that still the plan as that would be amazing? I'm clearly doing something wrong. Thx
     
  39. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi
    @MetalDonut

    The current version only offers networking support for the CharacterMovement component only, this is similar to Unity built-in CC, but with many features and advantages over it, so it's expected the Character will not work well, as it is not synced over net (yet).

    The Character class netwoking support is planned for the following update, but as commented previously, this will be as an example, as not all network games require to sync over the network all the Character class properties, so in the end, users decide.

    Regards,
    Krull
     
  40. MetalDonut

    MetalDonut

    Joined:
    Feb 7, 2016
    Posts:
    127
    Hey @Krull - Love that the network support for Character class is coming in the next update! Even if it's just an example, it will be enough for me to use to update on my side (I think). I really like this tool so want to stick with it for multiplayer. Any idea of how long the next update will be? Are we talking days, weeks, months or years? :)
     
  41. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi @MetalDonut

    Thank you, happy to hear you like ECM2!

    About your question:

    I am aiming to release the following update in about a couple of months, probably sooner if time (work) permits.
     
    MetalDonut likes this.
  42. Minzie

    Minzie

    Joined:
    Jul 26, 2019
    Posts:
    77
    Hi @Krull I just downloaded the latest version 1.3.1 (unity 2022.1.7f1, new input manager) but there are error messages relating to "simulation mode" as below. Can you pls help?
    upload_2023-2-19_15-22-45.png
     
  43. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi @Minzie

    Ah yes, those are due the update using unity 2022.2.7f1 (latest version) which modified the physics simulation related settings, so the preprocessor guard for 2022 version assumes its the latest 2022 version (2022.2.x) and use ne the newer settings which I think were introduced in 2022.2.xxx causing the issue.

    To solve this problem you could update to the latest 2022 version or remove the example (if not needed).

    Let me know if I can be of any further assistance.
     
  44. Minzie

    Minzie

    Joined:
    Jul 26, 2019
    Posts:
    77
    Thanks. I'll remove the example first. :)
     
  45. jiajialin1975

    jiajialin1975

    Joined:
    Jan 20, 2021
    Posts:
    5
    Hi @Krull
    I just bought ECM2 and import to my project. But I found the camera problem when I run "CM Third-Person Example Scene" in Playmode. The camera will switch between two position when I press "WSAD". It happen in random location without error message.
    Could you help me fix this cinemachine example scene?

    ECM2 version 1.3.1(input system new)
    Unity version 2021.3.19f1
    video below:
     
  46. ptm_oo

    ptm_oo

    Joined:
    Oct 30, 2014
    Posts:
    35
    Hi. Is there a feature that prevents character to move outside collider area? I mean like navmesh, ground bounds or ledge?

    This can be achieved by making invisible walls, or some raycast in front of player direction, but maybe there is more elegant solution already?
     
  47. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi @jiajialin1975,

    Thank you for reaching out.

    In order to better help you, I appreciate if could provide me additional information:

    Does this happen only in the Cinemachine Example?

    Is it a vanilla (un-modified) Cinemachine example?

    Having said that, I'll perform some tests and get back to you.

    Thanks!
     
  48. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    727
    Hi @ptm_oo
    For the current version, the only way for this is using the CharacterAgent, which extends a regular character adding navigation capability. It uses a NavMeshAgent, to move the character towards a desired location.

    Another option as you already commented, is using invisible walls, for this you can use trigger colliders, just make sure you set the CharacterMovement Trigger Interaction to Collide.

    Last but not least, it is planned to include a 'can walk off ledge' option in a future update, so when enabled it will prevent the character from walking off a ledge.
     
    ptm_oo likes this.
  49. jiajialin1975

    jiajialin1975

    Joined:
    Jan 20, 2021
    Posts:
    5
    Hi @Krull ,

    Thank you for reply

    Yes, this happen only in the "CM Third-Person Example Scene" , but the "CM First-Person Example Scene" is completely normal.
    FYI. Gameplay >> "Third Person Controller Example Scene" has no problem, either.

    Yes, it is a vanilla (un-modified) Cinemachine example. I delete three Cinemachine examples and unzip "Cinemachine Examples.zip" many times. They are vanilla (un-modified) Cinemachine examples.

    Sorry for the lack of information.

    If you need any help I will reply as soon as possible.
     
  50. One_Learning_Man

    One_Learning_Man

    Joined:
    Sep 30, 2021
    Posts:
    80
    Hello there Krull, hope you are doing well. How is Fish-Net for ECM2 going?

    EDIT: I was looking for the network example but it is in Character Movement, I found it. Thank you, looking forward to network ECM2.
     
    Last edited: Feb 24, 2023
    Krull likes this.