Search Unity

[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:
    771
    That's great! glad I could help and thank you for your kind comments :D
     
  2. homemacai

    homemacai

    Joined:
    Jul 22, 2020
    Posts:
    74
    Hello there, so I have been using ECM for a while now, mostly because it was not a Kinematic controller, as I cannot find one that works with Dynamic Water Physics 2. I finally updated to the new Kinematic version, but yet again I have the same problem as using other kinematic controllers.
    When on a boat, the character moves with it nicely, it does not rotate with the deck for some reason, but the real issue is when I walk around the boat, touching the walls and objects attached to it, the force used to move the character around breaks the boat physics, i can stop a ship, a really heavy one, just by touching a wall on the opposite direction that it is moving.
    Any advice if there is a way for this not to happen? Or should I go back to the non kinematic version?
    Thanks!
     
  3. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi @homemacai,

    A few things to try, set the Physics default (Project Settings->Physics->Default Contact Offset) to a lower value like 0.001f, this will prevent the Physics engine detect and response collisions since the Character 'keeps' an offset from others this could help to solve the problem.

    Another option is to disable the physical collision between the boat and the character's capsule collider, you can use the Character's CapsuleIgnoreCollision(boatCollider, true) function for this. It internally will use the Physics.IgnoreCollision function.

    About stopping it, yes this is due a kinematic rigidbody internally will be seen as an object with an infinite mass, so the best approach is preventing the physics engine determine collisions between those 2.
     
    homemacai likes this.
  4. homemacai

    homemacai

    Joined:
    Jul 22, 2020
    Posts:
    74
    Thanks! The first option didn't really helped, when I tried a bit harder the collision was registering and the boat stopping.
    But the second option worked perfectly, just what is really happening under the hood with this fix?
    The only thing I couldn't ever make work in all the versions, on the boats, is the platform rotation, but that is a minor issue. Now that the boat collision thing is fixed, my life improved considerably, thanks!
     
    Krull likes this.
  5. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Glad I was able to help you!

    The way it works, is because being a kinematic character controller, a character will only ever move when we explicitly call its Character Movement Move method, however the physics engine (PhysX) will see a kinematic rigidbody as a rigidbody with infinite mass so when other regular rigidbody (ie: your boat) collides with this, it will be pushed away.

    Disabling the capsule's physical collisions makes the character 'invisible' to the physics engine.

    To use a rigidbody as a platform, make sure set the following settings from your Character:

    Impart Platform Movement: true
    Impart Platform Rotation: true
    (only if you want your character rotate with your platform)
    impart Platform velocity: true (when enabled, will transfer platform's momentum to your character when leaves the platform)

    Enable Physics Interaction: false (or true if you want your character push other rigidbodies)
     
    homemacai likes this.
  6. jimmygladfelter

    jimmygladfelter

    Joined:
    May 3, 2020
    Posts:
    83
    I can successfully move around a loop now using the examples; however, when I sprint (when sonic turns blue its just ecm2 sprint with large acceleration and some particle effects), I can come out of the loop too early, see the video below:



    Any ideas on how I can make the character stay on the loop during high speeds?
     
  7. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi @jimmygladfelter

    I suggest you use the method I used in the attached package, where uses the character velocity to sample the 'next' position normal (raycasting), also, you can increase the character movement slope limit.

    Alternatively you can add a SlopeLimitBehavior component to the loop and set it to walkable.

    Btw your sonic game is looking good!
     
  8. coromo

    coromo

    Joined:
    Sep 23, 2018
    Posts:
    3
    Thank you for your thoughtful response.
    Sorry, I guess ECM2 was too difficult for me to understand. I will give up and consider another means.
     
  9. jimmygladfelter

    jimmygladfelter

    Joined:
    May 3, 2020
    Posts:
    83

    Thanks @Krull I actually am using your example controllers methods with raycasting. I'll have to check slope limit on character to see if that helps.
     
  10. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi @jimmygladfelter,

    I reviewed it and in my test it was caused by the rotation interpolation speed being too slow when a 'dash' is used, so the character detects the surface as non-walkable, i.e, the angle between surface and character's up axis is greater than slope limit, and depending of speed it could be over 90 degrees.

    Code (csharp):
    1.  
    2. Quaternion targetRotation = Quaternion.FromToRotation(GetUpVector(), targetNormal) * GetRotation();
    3. characterMovement.rotation = Quaternion.Slerp(characterMovement.rotation, targetRotation, 15.0f * Time.deltaTime);
    4.  
    To fix it, I increased the interpolation speed from 5 (attached example) to 15 and it worked fine. Probably you will need to tweak it a bit depending your speed settings.
     
  11. jimmygladfelter

    jimmygladfelter

    Joined:
    May 3, 2020
    Posts:
    83
    Awesome! Thank you very much for your time with support!
     
    Krull likes this.
  12. SRx734

    SRx734

    Joined:
    Sep 4, 2018
    Posts:
    8
    Hi @Krull ,

    I think there is a glitch about how ReachedJumpApex event triggers. It triggers as long as the vertical component of velocity relative to gravity is negative, but if the character performs a double jump while falling, it will trigger immediately when that second jump started.
     
  13. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi @SRx734,

    Thanks for reporting it. I will review it and issue a fixed update.

    As far as I remember, the current implementation checks when there is a change in vertical velocity (from positive to negative), so possibly some condition is causing it on a double jump.
     
  14. unity_kNAkg40A_6Vxwg

    unity_kNAkg40A_6Vxwg

    Joined:
    Jun 26, 2020
    Posts:
    4
    How can I AddForce to a character?
    I want to apply physical force with a script.
    I'm Japanese.
    I'm sorry I'm not good at English.
     
  15. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi,

    The Character class includes AddForce and AddExplosionForce methods, those works just like the unity rigidbody counterparts and an additional LaunchCharacter method which unlike others let you modify the character's velocity component wise.

    You can find the whole ECM2 API reference included in the Docs folder.

    Regards,
    Krull
     
    jcporcel likes this.
  16. Hukha

    Hukha

    Joined:
    Aug 12, 2013
    Posts:
    61
    Hello!
    I've tried a lot of character controllers before but none was what I was looking for...
    I need a controller that can have a "fake parent" function, basically be able to attach the controller to some object movement, even if its not standing on that object.
    My idea is to implement my climbing system with it, so should be able to disable collisions while climbing at the same time that "follows" the target (An animated platform/object/whatever) and then reenable it when finish climbing...
    This controller looks like what I was looking for, but not sure which I should get(I see ECC, ECC2 and Character Movement) and if fits as well as I think, can you clear my mind a bit more about it?
    Thanks, awesome asset!

    EDIT: Finally I bought the asset(ECC2) and tested a bit with the "SetPlatform()" and looks exactly what I was looking for, still a bit flickery but pretty sure is something about setup
    Still, if you have some hint of how you would do this approach with ECC2 please tell me
    Anyway, awesome asset!

    EDIT-2: I'm having a problem with disabling collisions, when I set a platform manually using SetPlatform() and the platform is moving, setting detectCollisions, PhysicsInteraction and constrainToGround I still have some of the collisions. For now my workaround is to set collisionLayers to nothing and then resetting original ones when I need them, but looks like a hacky way.
     
    Last edited: May 3, 2022
  17. Deleted User

    Deleted User

    Guest

    Trying to make ECM2 work as First Person Controller with full body character; I couldn't find any examples for this in the demos; would it be possible to point out to a starting point or maybe do a full example ?

    Ideally I would like to have the head bone (look IK?) 'controlled' by the mouse view; would that be possible ?
     
  18. unity_kNAkg40A_6Vxwg

    unity_kNAkg40A_6Vxwg

    Joined:
    Jun 26, 2020
    Posts:
    4

    it is complete! Thank you
     
    Krull likes this.
  19. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi @hukhak

    Thank you for purchasing ECM2!

    When using the SetPlatform or any platform in general just make sure you move your 'platform' in a fixed update so it be in sync with unity's physics, otherwise it could be desynced and cause jitter and strange behaviours.

    Now to disable collisions, you should use the Character DetectCollisions method, this disables the whole Character Movement collision and ground detection.

    Additionally you can use the IgnoreCollision method(s) to explicitly ignore one specific Collider or a Rigidbody causing it to ignore all the colliders attached to that rigidbody.

    While those functions will make the system ignore collisions, note dynamic Rigidbodies will still collide against a kinematic rigidbody (i.e character's capsule) so depending on your setup, probably will need to ignore this physical collision. Once again the Character class includes the CapsuleIgnoreCollision to make the Physics engine ignore collision between capsule and given collider. Internally it uses Physics.IgnoreCollision.

    The Physics interaction flag let you enable or disable the dynamic collision response or in other words, if the character can push or be pushed (affecting its velocity) by other rigidbodies. I.e. if disabled a character will 'see' dynamic rigid bodies as obstacles, otherwise it will push those.

    The constrainToGround property, let you indicate if the character should be snapped or not to the current walkable ground. This is a feature missing on Unity's built in cc and helps to correctly maintain the character on walkable ground and not be launched of ramps or bounce down stairs, etc.
     
  20. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi @onefoxstudio

    Yes, it includes a 'traditional' first person controller where the camera is positioned at a given pivot point.

    Honestly speaking I am not familiar with this implementation, so I'll need to review it before giving you some feedback and possibly consider adding a working example in the following update.

    And talking about updates, I would like to share that currently I am working on a 'networking' update where I'll be adding getting started examples for major unity's networking solutions, like Photon Fusion, Mirror, FishNet, etc. so keep an eye out for that :D
     
    ShiftedClock likes this.
  21. FergJoe

    FergJoe

    Joined:
    Dec 28, 2016
    Posts:
    19
    YES!!! I was just about to post and ask for a sample of Fusion integration!! Thanks for a great asset!! Any ETA?

    Also, I've been active throughout the Fusion Beta. The Fusion Dev team asked me to relay that they would be happy to help via Discord anytime.
     
    Krull likes this.
  22. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Well, while I can not provide a ETA it should no take that long, as it is progressing very well.

    Yes, I have talked with them (Hi Jiri :D) and totally agree with you, very kind and very helpful, amazing customer support!
     
  23. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    I did a quick test parenting the First Person Root node to the included Unity Character Head game object, and it carry the animation while allowing to control the camera as the regular first person rig.

    It works very well, but the included example animation is not the best for this, as it would need to correctly handle backwards and strafe movement like a First Person.
     
  24. apprenticegc

    apprenticegc

    Joined:
    Apr 21, 2012
    Posts:
    25
    Is there any sample for attack combo movement? I am trying to add attack movement into ecm2 but need some hint to start.
     
  25. mookfasa

    mookfasa

    Joined:
    Dec 21, 2016
    Posts:
    46
    @Krull

    Is there a way to get all colliders that our player is touching?

    I added
    Code (CSharp):
    1. characterMovement.Collided += OnCollided;
    to the OnDisable and OnEnable in my player controller. Then when I debug it OnCollided I can get the name. But I want to know all the colliders at any given time.
     
  26. One_Learning_Man

    One_Learning_Man

    Joined:
    Sep 30, 2021
    Posts:
    81
    @Krull Your CharacterMovement Walkthrough documentation is very helpful! I got 80% of the information I need from it. I wish there was a section on swimming and mass. I feel like a swimming section would be very useful since swimming = flying more or less.

    My theory:
    Swimming = manipulation of gravity, specifically Vector3.y component.
    Mass = manipulation of force.

    Is that what you did?
     
    Last edited: May 12, 2022
  27. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    It does not include a combo related example as it focuses more on movement mechanics.

    For a combo like system, I think you can handle it like a state machine, I mean your attack has different attack states and depending on your press timing and current state you move to the next combo state or reset it if missing your combo window timing.

    I think @Rin-Dev could provide a better help as he is actually developing a combo system :D
     
  28. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    The Collided method is called for each collision or overlap found during a character's movement. It passes a CollisionResult struct containing complete information about collisions found.

    Alternatively you can use the CharacterMovement GetCollisionResult method to iterate over all collision found during last Move call, i.e:

    Code (csharp):
    1.  
    2. int collisionCount = characterMovement.GetCollisionCount();
    3.  
    4. for (int i = 0; i < collisionCount; i++)
    5. {
    6.     CollisionResult collisionResult = characterMovement.GetCollisionResult(i);
    7. }
    8.  
    Last but not least, you can always perform an overlap test to query any touching colliders.
     
    mookfasa likes this.
  29. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Do you mean for Character Movement alone?

    ECM2 actually already implements a swimming movement mode with buoyancy. What it does at great sight is first disable ground constraint to allow vertical movement, as when constrained to ground the system ignores any vertical velocity component.

    Additionally it applies a proportional gravity affected by buoyancy setting. You can take a look at the Character Swimming method to get a better perspective of how it is implemented in ECM2.

    The mass is only for forces yes and to resolve collisions against dynamic rigidbodies or other characters to determine push results.
     
  30. LuiBroDood

    LuiBroDood

    Joined:
    Mar 13, 2019
    Posts:
    84
    be amazing if you made it work with FishNet and the prediction and features, i think i did it before lol but i have to go through it again
     
  31. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Yes, the update will add examples for Photon Fusion, FishNet both with prediction and reconciliation, and Mirror using isLocalPlayer usage as it do not includes prediction and reconciliation OOB.

    It will be two parts update, first using only CharacterMovement component (about to release this week) and a second update adding support for Character(s)

    Cheers!
     
    LuiBroDood and One_Learning_Man like this.
  32. One_Learning_Man

    One_Learning_Man

    Joined:
    Sep 30, 2021
    Posts:
    81
    This week?! That's awesome!
     
  33. w409544041

    w409544041

    Joined:
    Aug 3, 2017
    Posts:
    52
    Hi,dose ECM2 have Roadmap?or what is your plan in this year.i dont need a release time,just want to the asset where to go.thanks for your reply.
     
  34. w409544041

    w409544041

    Joined:
    Aug 3, 2017
    Posts:
    52
  35. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    302
    Hi, I am just going through all your docs/walk throughs. Would it be possible to add an example for leaning and proning in the future?

    Thanks

    Edit* Probably don't need prone as it just a copy of crouching with different values. Leaning I would be interested to see how you would approach it with and/or without cinemachine.
     
    Last edited: May 22, 2022
  36. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi,

    Not a strict roadmap is available as the CharacterMovement component (aka a Character Controller) is pretty much complete but the "Can Walk off ledges" feature. So basically future updates will be maintenance and adding examples and / or integration with other packages.

    For example, as you noticed I released the first update featuring networking integration, this will be followed with additional network related examples and adding networking support for Character based clases, i.e NetworkCharacter which is still in development and will be available next update.

    Obviously this does not mean I have done with ECM2 or CM as I plan to support it for a long time ;)

    It should as actually ECM2 do not do anything related with animation or force you to animate your character in a particular way. With ECM2 you read the character's state (ie. is grounded? its speed, its movement direction, is jumping? etc.) and use this information to sync your animation accordly.

    The same can be used for animator, animancer or even 2d sprites.
     
    w409544041 likes this.
  37. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi,

    Thanks for the suggestion, and yes for prone is basically a crouch as while the character can be rotated as needed for mario galaxy like games, its movement is related to its 'feet' area (capsule's bottom sphere).

    For the leaning, you mean something like this ?
     
  38. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    302
    Not like that.

    More like this


    and 15:08 on the second video:


     
    Krull likes this.
  39. TheMK-_-

    TheMK-_-

    Joined:
    Feb 8, 2018
    Posts:
    26
    @Krull Hi really enjoying the asset, even if I get a bit lost at times (so much stuff!). I really appreciate the new mirror/fishnet examples as I had been playing around with some networking tests and was delighted to see you were adding networking stuff to an already awesome character controller.

    Everything seems to be working fine in the mirror example scene but I was wondering how I would go about propagating it over to the FPS and Third person characters. Obviously, if your planning to do this yourself anyway I will gladly await the update. But if you haven't got an eta on that or were not planning that, any tips on were I might start would be appreciated.

    Many Thanks

    Mike C
     
  40. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    302
    Suggestion:

    In FirstPersonCharacter.cs on line 431, I think 6.0f should be exposed to the inspector as a variable like crouchSpeed or something similar. That is all. Thanks.

    Code (CSharp):
    1. protected virtual void AnimateEye()
    2.         {
    3.             // Modify camera's height to simulate crouching state
    4.  
    5.             float actualEyeHeight = IsCrouching() ? eyeHeightCrouched : eyeHeight;
    6.  
    7.             eyePivot.localPosition =
    8.                 Vector3.MoveTowards(eyePivot.localPosition, new Vector3(0.0f, actualEyeHeight, 0.0f), 6.0f * Time.deltaTime);
    9.         }
     
    Last edited: May 30, 2022
    TheMK-_- likes this.
  41. Krull

    Krull

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

    About your question:

    Yes, the current ECM2 update was to put it on par with CM current release adding its network related update and its examples, so all examples are pure CM based.

    The following ECM2 update will add Character based network examples, ie: NetworkCharacter and its corresponding First person and third person examples.

    This update is still in development and while I can not provide a fixed release date yet, the development is progressing really well :D

    Regards,
    Oscar
     
  42. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    A yes, Thanks for suggestion, will add it as part of next update.

    Cheers,
    Oscar
     
  43. bvonline

    bvonline

    Joined:
    Feb 27, 2021
    Posts:
    85
    I installed Easy Character Movement 2 and did not change any files or settings of my new Unity project. After that, I installed the Input System Package from Unity. To avoid problems, I reimported the Easy Character Movement 2 files (no deletion of the files, just reimport).

    I use unity 2020.3.34f1 (LTS) - latest Release.

    Do I have to consider anyithing to change / modify that it works properly? Because in the manual is written, that it is recommended to install the input system BEFORE installing Easy Character Movement 2.

    By the way - nothing special - I got this error:

    Couldn't find a readme
    UnityEngine.Debug:Log (object)
    EasyCharacterMovement.ReadmeEditor:SelectReadme () (at Assets/Easy Character Movement 2/ReadMe/Scripts/Editor/ReadmeEditor.cs:59)
    EasyCharacterMovement.ReadmeEditor:SelectReadmeAutomatically () (at Assets/Easy Character Movement 2/ReadMe/Scripts/Editor/ReadmeEditor.cs:26)
    UnityEditor.EditorApplication:Internal_CallDelayFunctions ()​

    Thanks for your help in advance!
     
    Last edited: Jun 2, 2022
  44. TheMK-_-

    TheMK-_-

    Joined:
    Feb 8, 2018
    Posts:
    26

    Oh that's great to hear.

    Thank you.
     
    Krull likes this.
  45. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi
    @bvonline,

    It should work fine as long as you enable the new input system. Please set your Active Input Handling to BOTH (Project Settings -> Player -> Other Settings -> Active Input Handling) so you can try all the included examples, even the one using the old input system.


    For your error message, it seems the readme welcome window is not being correctly loaded, for it, feel free to remove the ReadMe folder and the Readme asset file from the Easy Character Movement 2 folder. This should fix your current issue.

    upload_2022-6-2_22-13-16.png

    Regards,
    Krull
     
  46. SRx734

    SRx734

    Joined:
    Sep 4, 2018
    Posts:
    8
    Hi @Krull ,
    Do you have any suggestions on creating a 2d top down character? I'm currently using fly mode but I wonder if there are any better options? Thanks in advance.
     
  47. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi @SRx734

    While ECM2 can be used for 2D games (2.5D actually) it's 3D based, so for top down view games you basically move your character in the XZ plane and put the camera with a top view, pretty much like the included top down template scene.

    In the end, character movement remains the same, just the camera is changed. The same can be said for an isometric view a'la Diablo.

    Regards,
    Krull
     
  48. bvonline

    bvonline

    Joined:
    Feb 27, 2021
    Posts:
    85
    Thanks for your help before. I have a second usage case for your Movement asset, I am focusing on another game than a game with a typical human character.

    A tank has to be controlled. As tanks turn left / right, and maybe have a special way of turning around (like subtly sliding), do you think I could use your asset to - easily - turn it into a tank controller? Or should I better avoid it and start from scratch? I am asking, because I do not know the technical background of your asset.

    Thanks in advance!
     
  49. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi @bvonline ,

    Sure, you can use ECM2 to do a tank-like rotation, just need to modify the way to handle the character rotation.

    A Character by default will rotate towards its given movement direction, so in the case of a Tank you want to use the horizontal input to rotate around the character's Y-axis and the vertical input to control the forward / backward movement (character's forward).

    I created a basic example showing the above method and should help you to get started. To use it simply import the attached package into a project with ECM2 installed.

    Regards,
    Krull
     

    Attached Files:

    bvonline likes this.
  50. mookfasa

    mookfasa

    Joined:
    Dec 21, 2016
    Posts:
    46
    Hi @Krull ,

    Is there a way to lerp SetPosition and SetRotation?