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:
    558
    Hi @mookfasa,

    Well you can simply interpolate your transform position and rotation respectively, however worth note the character will only resolve its continuous collision based in its given velocity (the one passed to the CharacterMovement Move method) so while it will still resolve discrete collisions depending of your usage it can be enough or not.

    A more robust implementation when interpolating position should be passing the interpolation resultant velocity to the Move method so it performs the fully continuous collision along your given interpolated position.
     
  2. bvonline

    bvonline

    Joined:
    Feb 27, 2021
    Posts:
    42
    Thank you very much for your effort doing that tank script. Great help! Could be used for a demo video in the store, that it works also with tanks :) Have a good weekend.
     
    Krull likes this.
  3. Krull

    Krull

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

    Glad I could help :) and thank you for the suggestion, it's a great idea, I'll add a basic example in the following update!

    Regards,
    Krull
     
    bvonline likes this.
  4. LuiBroDood

    LuiBroDood

    Joined:
    Mar 13, 2019
    Posts:
    39
    any estimate how long full Fishnet integration is coming along?
    this controller is amazing !
    thanks
    i guess Fishnet updating alot recently too
     
  5. Asarge

    Asarge

    Joined:
    Jun 2, 2018
    Posts:
    5


    Hi Krull,

    I have a grapple in which I take off the constrainToGround when attached. When grounded & grappled ideally you would enter a water ski behavior but not entirely sure if these should be their own movement modes or are there some grounded check functions I can access while in falling mode for situations like the pic above (where I could reapply the ground constrain at this point)?
     
  6. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @LuiBroDood,

    No estimated release date yet, sorry. Having said that, the development is progressing well and hopefully won't take too long to release the update.

    Regards,
    Krull
     
    LuiBroDood likes this.
  7. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @Asarge,

    First of all let me tell your game looks great! :D

    About your question:

    You could use the PauseGroundConstraint method to temporarily disable the ground constraint, it will automatically re-enable it after its timer completes. This is what jumps do.

    The disable pause constraint (i.e: characterMovement.constrainToGround = false) is mostly used for movement mode changes, like flying, swimming so the constraint is disabled / re-enabled as mode changes.

    Regards,
    Krull
     
  8. Hukha

    Hukha

    Joined:
    Aug 12, 2013
    Posts:
    61
    Hello Krull!
    I'm having a bit of a problem with ECM2. I'm using it for all that my character movement needs and it's awesome, but not sure the next thing that I want to do is possible with it. I would like in a specific movement mode to have everything climbable/walkable, that means that walls can be ground also under certain circumstances.
    The problem with this is that when that happens, the character should be snapped to where is walking/climbing no matter what the gravity is, shouldn't be able to jump or "fall". (Easy to understand if you think in a ball sitck to the wall)

    Also the rotation of the capsule should change and that can be a problem too with ECM2, but can be fixed easier.

    This needs to be done because I want the character to move around edges etc

    Do you think there is a possible way to achieve this without disabling everything about the controller and writing my own?

    Thanks!
     
  9. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @Hukha,

    ECM2, while it includes default movement modes, one of its many strengths is its ability to be extended and let users build their own custom mechanics on top of ECM2.

    For cases like yours, I think a custom movement mode is the way to go, as what a movement mode does is set the rules on how a character will be moved and it can include sub-states (if needed) as you can see in the ladders examples.

    In this custom mode, your character won't be affected by gravity or be able to jump (unless you want), a custom movement mode basically lets you control how the character's velocity is modified as you can see in the included default modes

    Let me know if I can help you any further.

    Regards,
    Krull
     
  10. Asarge

    Asarge

    Joined:
    Jun 2, 2018
    Posts:
    5
    Hello and thank you Krull,

    I tried using PauseGroundConstraint as well and could likely toggle it to velocity so I could launch off jumps while grappling but it does function very nicely currently while in falling mode and sliding along ground.

    Ideally I would like to be able to access whatever ground check functionality so I can have it work in other movement modes and also match the same detection used in ECM2. I can't find the exact reference chain or documentation to do this properly if you know how I can achieve this.
     
  11. ge01f

    ge01f

    Joined:
    Nov 28, 2014
    Posts:
    104
    I've tried a few different things to make the character launch without it being a Jump, I think this is correct:


    Code (CSharp):
    1.                     Character.PauseGroundConstraint(5f);
    2.                     Character.LaunchCharacter(velocity, true, true);
    3.  
    But it doesnt work. The velocity Vector3 definitely has a Y component, all values are set, but it still moves on the plane of the ground.

    I also tried:
    Character.AddForce(velocity, ForceMode.VelocityChange);

    And I tried setting the `Movement.constrainToGround` manually, and none of them let the character leave the ground. The default movement is walking, but with the Pause I thought this would work.

    What am I missing?
     
  12. VeryHotShark

    VeryHotShark

    Joined:
    Mar 11, 2017
    Posts:
    9
    Hi I wanted to ask how does ECM2 compare to the kinematic character controller asset made by Philippe st Amand? https://assetstore.unity.com/packages/tools/physics/kinematic-character-controller-99131#publisher

    I'm wondering which one to buy and both seems pretty similar

    Thank you
     
  13. ge01f

    ge01f

    Joined:
    Nov 28, 2014
    Posts:
    104
    Krull and Rin-Dev like this.
  14. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @Asarge

    ECM2 through its CharacterMovement component offers a great amount of valuable data to retrieve, from your Character you access collision info (CollisionResult struct) overriding the OnCollided event and to retrieve ground info (FindGroundResult struct) overriding it's OnFoundGround method. Alternatively, you can directly subscribe to the CharacterMovement Collided and FoundGround events to retrieve the same data.

    The CharacterMovement also exposes this info through its currentGround property, and lets you iterate through collisions found during last Move call if preferred using the GetCollisionCount() and GetCollisionResult() methods.

    Lastly, the CharacterMovement component exposes the internal methods used to perform ground detection so you can use those same methods when implementing custom mechanics (vault, climb, etc) to ensure proper ground detection continuity, the methods are FindGround and ComputeGroundDistance methods, this highly flexible functions let you override the character's position so you can use those to validate desired positions, sample a position, etc.

    I suggest you take a look at the API Reference for the CharacterMovement component, as it offers a great amount of functions to ease your development with it.

    Regards,
    Krull
     
  15. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @ge01f

    That seems correct to me, as it's exactly the same approach used in the Jump method, bouncers, etc.

    Worth note the PauseGroundConstraint is only needed when your character is in walking movement mode, as other modes, like flying and swimming, disable the ground constraint and re-enable when the mode is changed.

    Worth noting a character, (being a kinematic character) won't do anything unless you call its CharacterMovement.Move method, possibly the missing piece of your code?

    I suggest you take a look at the Character Move() method and its DoJump() method to see the PauseGroundConstraint use during the jump.

    Regards,
    Krull
     
  16. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @VeryHotShark

    First of all thank you for your interest in ECM2!
    About your question:

    They are similar as both are character controllers, pretty much like unity's built-in character controller , i.e: A specialized component aimed to perform collision constrained character movement.

    While they share the same category and some features, they also differ a lot in features and implementation. ECM2 it's basically two products in one, the CharacterMovement component, this like KCC, it's the character controller used by ECM2 and works as a direct replacement for unity's built in character-controller and follows the same ease to use approach, a single Move method call, once again just like built-in CC.

    ECM2 adds a higher level Character based on top of its character controller (the CharacterMovement component), this Character based classes implements a highly configurable friction based movement model and built in common character movement modes and mechanics like walking, sprinting, falling, flying, swimming, crouching, jumping, root motion support, etc.

    ECM2 includes specialized Character classes like, FirstPersonCharacter, ThirdPersonCharacter, AgentCharacter, etc, to serve you as a strong foundation to build your game mechanics on top of it as it has been developed to be ease to work with (as-is) and easy to extend.

    Hope this helps you, however if you have any further questions, please let me know.

    Best regards,
    Krull
     
  17. ge01f

    ge01f

    Joined:
    Nov 28, 2014
    Posts:
    104
    Yes, thats what I was missing. Thank you.
     
    Krull likes this.
  18. angellnetwork

    angellnetwork

    Joined:
    Feb 8, 2018
    Posts:
    3
    Is not working at all with Unity 2021.3.3f1 LTS i get 29 errors about the input system all though it is installed, i also provided you with a screenshot so you can help me, thanks.

    this is one of the 29 errors i get.
    Assets\Easy Character Movement 2\Characters\Source\Characters\AgentCharacter.cs(3,19): error CS0234: The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
     

    Attached Files:

  19. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hello @angellnetwork ,

    This is strange, as it definitely seems to be missing the input system but you already have installed and enabled it...

    I suggest you create a new clean project and import the ECM2 package, (it will show errors since the input system package will not be installed), once ECM2 package has been installed, please install the unity input system (1.3.0 Release), it should fix the missing input system errors.

    I did a quick test using the same unity version and it worked following the above procedure.

    Let me know if I can help you any further.

    Regards,
    Krull
     
  20. NexonVision

    NexonVision

    Joined:
    Aug 30, 2018
    Posts:
    7
    is there a way to replicate moving on a slippery surface. ex: you run on ice and after you stop pressing any movement keys you will slide for a little bit.
     
  21. LunaTrap

    LunaTrap

    Joined:
    Apr 10, 2015
    Posts:
    117
    Hello! I bought this beautiful asset to make my 2.5d platformer and I'm loving it! I might come back with some questions on how to achieve certain tricks, like moving sand to make my character sink slowly but I think I can achieve the effect with physics volumes if I'm not mistaken, will report back if I fail to do it
     
  22. LunaTrap

    LunaTrap

    Joined:
    Apr 10, 2015
    Posts:
    117
    I also think I know how to achieve jump thru platforms, Using the one-way platform example I can just use another trigger on the other side to trigger only on a button press to make the character ignore the platform so it drops thru the platform. I think I know how it's done, otherwise I will ask here if I fail to do it on my own, Loving the asset!
     
  23. LunaTrap

    LunaTrap

    Joined:
    Apr 10, 2015
    Posts:
    117
    Update! I was able to implement the 2-way thru platform and I even added a background camera to render the platform behind the character. I love this asset!

     
    Krull likes this.
  24. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @NexonVision,

    Sure, the character's movement (when on walkable ground) is modeled using the Max Walk Speed, Max Acceleration, Braking Deceleration Walking and Ground Friction. From this, you can set braking deceleration to zero and tweak your movement usini the Max Acceleration (velocity rate of change) and the Ground Friction (affects changes in direction).

    To model a slippery movement, try setting the Braking Deceleration Walking to zero, the Max Acceleration (i.e: 8) and the Ground Friction to a lower value (i.e: 1), this will simulate a slippery surface.

    Regards,
    Krull
     
  25. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @LunaTrap,

    First of all thank you for purchasing ECM2 and happy to hear you like it!

    About your question(s):

    Sure thing, feel free to post questions here (or through support email) while I prefer email support, posting here will help others in the same situation.

    The physics volume at great sight is a just trigger with the difference the character enters / leaves this volume until the character's center is in or out of it, unlike regular triggers, and obviously the addition to modify the character's state.

    Yes, the included example is jump-up only, but as you commented you can use another trigger to do the jump-down part in a similar way.

    Looking great! pretty clean implementation. Let me know if you need further assistance.

    Cheers,
    Krull
     
  26. AqueductGames

    AqueductGames

    Joined:
    Dec 18, 2018
    Posts:
    2
    Hello,

    How would I go about making it so the character moves relative to it's parent instead of relative to the world? Currently, if I parent the player to a moving and rotating platform it does not work as intended. I would want the player to use it's local coordinate to handle movement instead of using the world coordinates.

    Is there any way to achieve that?

    - Zachary
     
  27. Zultron

    Zultron

    Joined:
    Dec 26, 2012
    Posts:
    43
    Hi, there how would I go about detecting which foot is in a walk cycle is currently off the ground?

    The goal is to have the character naturally stop with the same foot that was ahead in the animation cycle at the moment the player wanted to stop the character.

    Ideally, I need to play the animation depending on the foot and inputmagnitude in the walk cycle. Any input would be appreciated @Krull

    I see there is jumpleg method which is close to what I am trying to do but not quite would it be better to use animatorpivotweight?
     

    Attached Files:

    Last edited: Jul 22, 2022
  28. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi Zachary,

    ECM2 automatically handles the moving / rotating platform for you, I mean, you no need to do anything in particular (no need to parent it), just make sure to set the impart platform movement, impart platform rotation and impart platform velocity properties to true.

    Additionally, it allows you to explicitly attach this to a moving 'platform' so it does not depend on ground state using the CharacterMovement SetPlatform function and SetPlatform(null) to detach from 'platform'.

    Regards,
    Krull
     
  29. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    302
    Hi, in my game I want to play different landing animations based on whether my character jumped before landing or he just fell from higher ground and landed. The most obvious way for me was to check in OnMovementModeChanged callback if the current mode is Falling and if IsJumping() is true or not. But this hasn’t worked because _isJumping variable are set after movement mode is set to Falling so when the callback is firing isJumping is always false. I placed movement mode after isJumping and it’s working now but I would love to not have to change Character.cs because I'd need to manually copy all the changes when a new version of this script is released. Maybe there is another way to check this?

    Also I've found that IsJumping is always true while you hold the jump button. This seems strange because there’s another variable for this — jumpButtonPressed and because of this you can’t actually check if you are truly jumping or not.

    Btw, in fall damage example landing callback is not firing consistently if the character is jumping in place. I suppose it's because of the float precision when you compare fallenDistance with zero. You can easily check this by opening fall damage example and jump in place a few times — Debug.Log will not show in console on every jump.
     
  30. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @Onigiri ,

    For this, you can use Character events such as OnJumped, OnReachedJumpApex, OnLanded, etc, and use the characterMovement.landedVelocity to determine how fast it landed and react accordingly. You can find the working example in the 3.1 Character Events folder (Easy Character Movement 2\Characters\Examples\3.- Events\3.1.- Character Events) .

    The OnMovementModeChanged it's basically a FSM enter / exit method triggered when movement mode is changed.

    About the fall damage example, I'll need to review it as it could be a bug. Thanks.

    Regards,
    Krull
     
  31. Asarge

    Asarge

    Joined:
    Jun 2, 2018
    Posts:
    5
    Hi Krull,

    I'm having troubles resetting my transform smoothly, if I do if (transform.up = Vector3.up) { originalRotation = true; } the character will sometimes lock up and freeze. If I do this angle check and then apply a safety reset it will prevent the lock but look a bit snappy (perhaps due to the custom OnLateFixedUpdate?).

    How can I properly reset the transform smoothly?

    Code (CSharp):
    1.     protected override void UpdateRotation()
    2.     {
    3.         base.UpdateRotation();
    4.  
    5.         if (originalRotation == false)
    6.         {
    7.             Quaternion r0 = transform.rotation;
    8.             Quaternion r1 = Quaternion.LookRotation(transform.forward, Vector3.up);
    9.             Quaternion lerpRotationReset = Quaternion.RotateTowards(r0, r1, 2.4f); //120f * time
    10.             if (!grappleAttached)
    11.             {
    12.                 transform.rotation = lerpRotationReset;
    13.             }
    14.             if (Quaternion.Angle(r0, r1) < Mathf.Epsilon)
    15.             {
    16.                 transform.up = Vector3.up;
    17.                 originalRotation = true;
    18.             }
    19.         }
    20.     }
     
  32. FGRivera

    FGRivera

    Joined:
    Jun 3, 2013
    Posts:
    4
    Hi Krull!
    I am absolutely loving ECM2 and am so impressed with how comprehensive and flexible it is. I have a couple of questions if you don't mind:
    1) What is the difference between Braking Deceleration Falling and Falling Lateral Friction. They both seem to do the same thing in increasing how quickly you stop moving laterally while in the air.
    2) Is there any way we can tweak friction for the the Collide-and Slide? Particularly, I want to reduce sliding while in the air. Increasing Falling Lateral Friction gives me this result, but I want to be able to maintain the momentum of having little to no friction when not colliding.

    Thanks!
     
  33. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558

    Hi @Asarge,

    The LateFixedUpdate is used so the character is in sync with physics and moved / updated using a fixed timestep and most important to be interpolated (please make sure your character's rigidbody has interpolation enabled) that's the only difference of using the LateFixedUpdate method, and actually the built-in CC behaves the same way IF moved inside the LateFixedUpdate, it will be in sync with physics using a fixed timestep AND interpolated.

    To reset the character's rotation to world-up I suggest you update the characterMovement.rotation instead of the transform.up, as internally it update collider rotation too, i.e:

    Code (CSharp):
    1. // To instantly set character's up
    2. Vector3 targetNormal = Vector3.up;
    3. characterMovement.rotation = Quaternion.FromToRotation(GetUpVector(), targetNormal) * GetRotation();
    Or
    Code (CSharp):
    1. // To smoothly align the character's up-axis
    2.  
    3. Vector3 targetNormal = Vector3.up;
    4. Quaternion targetRotation = Quaternion.FromToRotation(GetUpVector(), targetNormal) * GetRotation();
    5.  
    6. characterMovement.rotation = Quaternion.Slerp(characterMovement.rotation, targetRotation, 5.0f * Time.deltaTime);
    Regards,
    Krull
     
    Asarge likes this.
  34. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @FGRivera

    Thank you, happy to hear you like ECM2! :)

    About your questions:

    Braking Deceleration Falling is a constant deceleration value applied only when no input is detected, most of the time this should be set to zero, however if you want a more instant 'stop' you can use it.

    Falling Lateral Friction is the friction applied when character is falling, this at its default value (0.3) works as air drag, however the friction affects the change in movement direction where a higher friction value offers a more snappy movement.

    No without modifying the CharacterMovement core code, however, you can simply modify the character's velocity as needed this should give you the effect you are looking for, for this you can override the Character CalcVelocity method as this is the method responsible of compute a new velocity for the given state, applying the effects of friction or braking friction and acceleration or deceleration.

    Let me know if you need any further assistance.

    Cheers,
    Krull
     
  35. NJ333

    NJ333

    Joined:
    Jan 31, 2021
    Posts:
    4
    Hi, I want to create AI movement with perfectly synced animations. What is the best way to do it? As my current understanding there are 2 ways to achieve it:
    1. I can turn on root motions and animation will take control over movement.
    2. I can turn off root motions and use navmeshagent's velocity to correctly set animation parameters (imagine I have movement x and movement z float parameters). on the animator controller side inside "2D Freedom Directional Blend Tree" I can use compute positions feature and correctly compute pos X and pos Y for my custom animations.
    I am struggling which is the better way to go. I see there is Top-Down character example but that character uses pre defined values in Agent Character component such as Rotation Rate, Max Walk Speed... I don't know from were you got those values. Thanks!
     
  36. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @NJ333,

    You are right as there is no specific way as ECM2 does not use animations or requires your animation be authored in a particular way. With ECM2 you are free to author your animations as you prefer, but you use your character state data (i.e: its speed, is grounded, is jumping, is falling, etc.) to sync your animation with the required data for animations, be it using an animator or any other solution like animancer for example. Please take a look at the API reference to check all the data available to read from your character.

    You can get a lot of character state information from the Character class and the CharacterMovement (analogue to unity's built-in CC).

    Hope this helps, however if you have any further questions please let me know.

    Best Regards,
    Oscar
     
  37. Nate_Osso

    Nate_Osso

    Joined:
    May 24, 2022
    Posts:
    1
    Heya, Krull. Is there still a discounted upgrade path?
    Thinking about starting a side project and upgrading to ECM2.
     
  38. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @Nate_Osso

    Sure, you can upgrade from ECM1 or CharcterMovement to ECM2, just make sure to log in with your account owning one of the other assets so the upgrade discount shows.

    Regards,
    Krull
     
    cursedtoast likes this.
  39. cursedtoast

    cursedtoast

    Joined:
    Apr 27, 2018
    Posts:
    50
    Thanks! Didn't realize I was still on my work account.

    The current discount threw me off, but i see it goes down three more dollars when on the correct account haha. I gather the asset went up in price a bit (understandably so, seems a lot has gone into ECM2) so it makes more sense now!

    I'm a big fan of the original and used it quite a bit, so I'm excited to check out the new system when I can upgrade.

    Cheers, and thank you!

    Edit: okay I upgraded and spent a few hours reading the docs and sample code. This is pretty nice! It feels very UE inspired, which is a great thing imo.
     
    Last edited: Aug 9, 2022 at 3:31 AM
  40. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    558
    Hi @cursedtoast

    That's great! Thank you for the upgrade and happy to hear you like it.

    Very true ::D, big fan of Unreal Engine CharacterMovement component so decided to base mine from it BUT following the easy to use Unity workflow we all love!

    Regards,
    Krull
     
    cursedtoast likes this.
unityunity