Search Unity

[RELEASED] Easy Character Movement 2

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

  1. Fabbs

    Fabbs

    Joined:
    Dec 2, 2013
    Posts:
    43
    I am using your demo scene with the rotating yellow platforms and the first person prefab with Platform Movement, Impart Platform Rotation and Impart Platform Velocity enabled.
     
  2. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    I tried the demo scene and honestly don't see or have any issue, it's working as it should. Actually in ECM2 platforms are first class citizens, where its usage is fully transparent for users, be it animated, scripted or even fully simulated rigidbodies like you can see in the following video, the character is using a fully simulated vehicle as a platform (Edy's vehicle physics).



    I suggest you create a new Unity project and import ECM2 latest version trying to isolate it.

    If the issue persists, could you provide me with the steps to reproduce it?
     
  3. One_Learning_Man

    One_Learning_Man

    Joined:
    Sep 30, 2021
    Posts:
    81
    I'm not sure I understand ground friction slider. I expect a friction of 0 should have the player sliding at current speed indefinitely like on frictionless ice for example but it doesn't really seem to do anything.
     
  4. Fabbs

    Fabbs

    Joined:
    Dec 2, 2013
    Posts:
    43
    Ok, Made a completely new project with only your ECM2. I loaded up the Scene with the rotating yellow platforms. In the rotating platform script i set the speed to 1. When standing on the rotating platform i do not move with it, but if i put the speed up to 10 on the platform i do start moving with it.
     
  5. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    The ground friction works as it should, however by the character braking (no input received) is also affected by the Braking Deceleration setting (default to 20 m/s) , this lowers the velocity constantly at the specified rate when no input is received. You can freely set it to zero so your character movement will be affected by friction and acceleration value only.
     
    Last edited: Mar 21, 2022
  6. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Ah yes, I was able to reproduce it in the ECM2_Demo scene, this happens because the Character from the demo scene has an assigned Min Move Distance (Character Movement -> Advanced -> Min Move Distance) to 0.005f, so it wont move at all until the given movement distance (i.e: platform velocity * deltaTime) is greater than this value.

    I suggest leave Min Move Distance set to 0 (default value).
     
  7. One_Learning_Man

    One_Learning_Man

    Joined:
    Sep 30, 2021
    Posts:
    81
    Settings ground friction to 0 and braking deceleration to 0 still have the character stopping so fast when applying the opposite direction. That doesn't seem right to me.



    I am looking for a way for an ice skater to rotate to the opposite direction but still slide in the current direction.

    Also what is Separate Braking Friction? Nothing in the documentation about it.
     
  8. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Try using a lower Max Acceleration value, for example 8. Actually ECM2 uses the exact same physical model as Unreal Engine Character Movement (thus its name!), a AAA battle tested physical model for character movement.

    You can safely leave the Braking Deceleration Walking to 0 and model your desired movement using the Ground Friction and Max Acceleration values. Where acceleration defines the velocity rate of change and friction affects change in direction, so higher values offers a more snappy movement. Probably you would need to change the character's rotation rate or rotation method to tank-like rotation.

    I think for a more accurate skate model, you would want to implement something close to 'one-tire' vehicles, where you basically cancel / reduce velocity lateral component as described in following video



    With ECM2 you can easily replace its physical model overriding the Character CalcVelocity method, this will let you completely replace the velocity calculation formula, for example:

    Code (CSharp):
    1. public class MyCharacter : ThirdPersonCharacter
    2. {
    3.     // TODO Add your game custom code here...
    4.  
    5.     protected override Vector3 CalcVelocity(Vector3 velocity, Vector3 desiredVelocity, float friction, bool isFluid = false)
    6.     {
    7.         if (IsWalking())
    8.         {
    9.             // New 'physical' model using a simple lerp
    10.  
    11.             return Vector3.Lerp(velocity, desiredVelocity, 1f - Mathf.Exp(-groundFriction * Time.deltaTime));
    12.         }
    13.  
    14.         // Default physical model
    15.  
    16.         return base.CalcVelocity(velocity, desiredVelocity, friction, isFluid);
    17.     }
    18. }
    By default a character will use the friction for each of its movement mode, i.e Ground Friction value when Walking, Falling Lateral Friction when Falling etc. However its often needed to override those values to achieve desired effect and instead of having to save / restore those values, you can simply use the Braking Friction.

    When Use Separate Braking Friction is enabled, the character will use the Braking Friction value as its current movement mode braking friction (no input is received).

    Please take a look at the 5.5.- Dash example where it use the Braking Friction to bypass character's current friction while dashing.
     
    One_Learning_Man likes this.
  9. One_Learning_Man

    One_Learning_Man

    Joined:
    Sep 30, 2021
    Posts:
    81
    @Krull Your suggestions made the movement much better ty.
     
  10. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Great, glad I could help! :)
     
  11. apprenticegc

    apprenticegc

    Joined:
    Apr 21, 2012
    Posts:
    25
    Hello Krull,

    Is there any sample I can can check to know if the character standing on the rolling object(wood for example) that will be making this character gradually spinned away then dropping?
     
  12. Krull

    Krull

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

    Sure, you can get all ground related information through the CharacterMovement currentGround property, or individually like characterMovement.isGrounded, characterMovement.groundCollider, etc.

    This is the whole FindGroundResult data returned by characterMovement.currentGround property:

    Code (CSharp):
    1. public struct FindGroundResult
    2. {
    3.     /// <summary>
    4.     /// Did we hit ground ? Eg. impacted capsule's bottom sphere.
    5.     /// </summary>
    6.  
    7.     public bool hitGround;
    8.  
    9.     /// <summary>
    10.     /// Is the found ground walkable ?
    11.     /// </summary>
    12.  
    13.     public bool isWalkable;
    14.  
    15.     /// <summary>
    16.     /// Is walkable ground ? (eg: hitGround == true && isWalkable == true).
    17.     /// </summary>
    18.  
    19.     public bool isWalkableGround => hitGround && isWalkable;
    20.  
    21.     /// <summary>
    22.     /// The Character's position, in case of a raycast result this equals to point.
    23.     /// </summary>
    24.  
    25.     public Vector3 position;
    26.  
    27.     /// <summary>
    28.     /// The impact point in world space.
    29.     /// </summary>
    30.  
    31.     public Vector3 point => hitResult.point;
    32.  
    33.     /// <summary>
    34.     /// The normal of the hit surface.
    35.     /// </summary>
    36.  
    37.     public Vector3 normal => hitResult.normal;
    38.  
    39.     /// <summary>
    40.     /// Normal of the hit in world space, for the object that was hit by the sweep, if any.
    41.     /// For example if a capsule hits a flat plane, this is a normalized vector pointing out from the plane.
    42.     /// In the case of impact with a corner or edge of a surface, usually the "most opposing" normal (opposed to the query direction) is chosen.
    43.     /// </summary>
    44.  
    45.     public Vector3 surfaceNormal;
    46.  
    47.     /// <summary>
    48.     /// The collider of the hit object.
    49.     /// </summary>
    50.  
    51.     public Collider collider;
    52.  
    53.     /// <summary>
    54.     /// The Rigidbody of the collider that was hit. If the collider is not attached to a rigidbody then it is null.
    55.     /// </summary>
    56.  
    57.     public Rigidbody rigidbody => collider ? collider.attachedRigidbody : null;
    58.  
    59.     /// <summary>
    60.     /// The Transform of the rigidbody or collider that was hit.
    61.     /// </summary>
    62.  
    63.     public Transform transform { ... }
    64.    
    65.     /// <summary>
    66.     /// The distance to the ground, computed from the swept capsule.
    67.     /// </summary>
    68.  
    69.     public float groundDistance;
    70.  
    71.     /// <summary>
    72.     /// True if the hit found a valid walkable ground using a raycast (rather than a sweep test, which happens when the sweep test fails to yield a walkable surface).
    73.     /// </summary>
    74.  
    75.     public bool isRaycastResult;
    76.  
    77.     /// <summary>
    78.     /// The distance to the ground, computed from a raycast. Only valid if isRaycast is true.
    79.     /// </summary>
    80.  
    81.     public float raycastDistance;
    82.    
    83.     /// <summary>
    84.     /// Hit result of the test that found ground.
    85.     /// </summary>
    86.  
    87.     public RaycastHit hitResult;
    88. }
     
  13. baumxyz

    baumxyz

    Joined:
    Mar 31, 2017
    Posts:
    107
    Hi @Krull

    I use an Animator component for my moving platforms. I created the animation using the Animation Window. I have set the animator to Animate Physics. The problem is that my character on the moving/rotating platform does not move with it.

    I then saw that there is a script for this called Animated Platform. Here, however, a Playable Director is required - I'm currently not using Playable Director components at all. Does this also work somehow with very simple animations and an animator?

    Thanks in advance!
     
  14. Krull

    Krull

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

    The playable director is not longer a requirement since some versions.

    Current versions support rock-solid transparent platform support without user having to write custom scripts or do anything.

    To use an animated platform just make sure you set its AnimatorUpdateMode to AnimatePhysics.

    Cheers,
    Krull
     
    baumxyz likes this.
  15. baumxyz

    baumxyz

    Joined:
    Mar 31, 2017
    Posts:
    107
    Oh, I didn't know that. Haven't updated ECM2 since July 2021. Can I update without hesitation and are the newer versions backward compatible? (Of course I make a backup before)
     
  16. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Well, there are some significatives changes and while I tried to minimize breaking the code, unfortunately there are a few data changes (outlined in release and change notes).

    Actually the current version is a completely new fully kinematic CharacterMovement component with many advantages over previous version, however as a result of this there are some data structures and variables modifications you should be aware of when updating.

    So I strongly suggest try the update in a separate project so you keep original safe while updating. Also if have questions or need help, let me know it.
     
    baumxyz likes this.
  17. baumxyz

    baumxyz

    Joined:
    Mar 31, 2017
    Posts:
    107
    Thank you for your explanation. In that case, I'll just copy the project and test the update separately. It would be interesting to see if my custom character controller script still works. :)
     
  18. VinnMarty

    VinnMarty

    Joined:
    Jan 6, 2019
    Posts:
    3
    Hi @Krull, hope you're doing well!

    So it's been quite a while since I've used ECM2 and I recently deleted it from my project and reinstalled it after the big update you did as I was very interested in the new seamless platform implementation, but I've been running into a kind of "stutter" when my platform goes up/down and I can't seem to fix it so far.

    I've uploaded two videos to show the problem I'm having (apologies if the scene is a bit dark/hard to see) using both the provided first-person and third-person Cinemachine examples (you can see on the third-person one that the character's feet keeps going inside the platform model):



    About the platform, it moves using animation and its Update Mode is already set to "Animate Physics". Furthermore, I tried checking the "Impart Platform Movement/Rotation/Velocity" boxes on both the Character Movement script and the CM Third/First-person Character Scripts that are attached to the example characters, but those didn't seem to change anything, so I'm wondering if I'm doing something wrong.

    Thanks in advance for the help!
     
  19. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    It should work well after fix the new data members I commented, however if need help, let me know.
     
    baumxyz likes this.
  20. Krull

    Krull

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

    When you want any platform interaction, please make sure you enable impart platform movement, impart platform rotation (if want rotate with platform) and impart platform velocity to transfer platform's momentum to character.

    In your case, please make sure your platforms has a kinematic rigidbody on it and ints interpolate property is set to Interpolate.

    For a complete working example, please take a look at the included 4.2.- Animated Platform example.

    Please let me know if need any further help.
     
    VinnMarty likes this.
  21. Fabbs

    Fabbs

    Joined:
    Dec 2, 2013
    Posts:
    43
    Sadly doesnt change anything, in a completely empty project with only ecm2.
     
  22. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    302
    What is the difference between the 'Character Movement' asset and 'Easy Character Movement 2' asset?
     
  23. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72
    Character Movement the movement component, ECM2 uses it and includes a controller and many examples of how you can use it, ECM2 includes the Character Movement asset. @Krull can give you more details.

    If you are after as asset you can plug into your game ecm2 if you want a robust movement component that you want to build your own component then just character movement
     
    Krull and giraffe1 like this.
  24. Krull

    Krull

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

    Yes, as @Broudy001 already commented, ECM2 it's basically 2 packages in 1, the CharacterMovement and the Characters.

    The CharacterMovement component, this is a very robust feature rich character controller, just like the Unity's built-in character controller but with many features and advantages over it.This can be considered as a low level component as its expected for developers to build their own movement mechanics on top of it, or use it as a comprehensive alternative to replace the built-in cc from already developed custom controllers.

    By other hand ECM2 uses the CharacterMovement component as its character controller, and adds a higher level layer Character classes which already implements common characters movement modes like walking, running, jumping, sprinting, flying, swimming, etc. among the many features it offers so developers can leverage this to build their own game mechanics on top of it.
     
  25. Zultron

    Zultron

    Joined:
    Dec 26, 2012
    Posts:
    59
    I am considering the asset right now but I noticed that there has been no stress test video visible. How many agents the asset can support running at the same time with all physics?

    As an example, the Character Controller Pro by Light bug can run around 400 before a serious performance impact and
    Kinematic Character Controller by Philippe can support around 1000 agents at the same time and at 60fps.

    Also, how do you distinguish yourself from these two assets?
     
  26. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hello @Zultron,

    First of all thank you for your interest in ECM2!

    About your question:

    It includes a stress test included in the CharacterMovement examples folder. In my development machine, I got about ~150 fps for 2000 characters and about ~70 fps for 1000 characters, as you can see in attached images from included example:

    Captura de pantalla (19).png

    Captura de pantalla (21).png

    I definitely think my package it's simply the best character controller for Unity but obviously I am biased.

    ECM2 it's basically two packages in one, first the CharacterMovement component, a AAA fully kinematic character controller and a comprehensive alternative to Unity's built-in Character Controller, but with many features and advantages over it; for example you can easily replace the unity's cc with my CM from starters assets pretty easy, keeping the same code just replacing cc calls with cm calls, I posted the modified script here.

    My package it's based on unreal engine character movement component (hence its name) and aims to offer the same quality as unreal counterpart, for example my ground detection is the only based on real surface normal (not capsule cast one) a MUST in order to correctly determine if a collided surface is 'walkable' or not, among many features included.

    Another really nice feature, is the transparent platforms support without you having to do anything, be it scripted, animated, tweened, or even fully simulated rigidbodies like boats, vehicles, etc. For example here you can see a character on an Edy's vehicle.



    On top of the included CharacterMovement component ECM2 includes a feature rich Character based components which includes built in typical movement modes like walking, running, sprinting, falling, flying, swimming, etc. So users can easily extend this characters adding their game mechanics on top of it. This features a highly configurable friction based physical model to customize your character's movement.

    Let me know if I can be of further help.
     
    Last edited: Apr 11, 2022
  27. AFarrell

    AFarrell

    Joined:
    Apr 24, 2016
    Posts:
    18
    Hello there!

    I was wondering how best to approach a Timeline based cutscene. If a character walked into a trigger volume, the Timeline Director would activate and provide the exact motion, and move the Character Root node as well. I would also want to disable any physics based movement at this time as well.

    Any help would be appreciated!

    Cheers:)
     
  28. Krull

    Krull

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

    You can disable a character, setting its movement move to None (i.e. SetMovementMode(MovementMode.None)) , when disabled a Character behaves like a regular transform, so you can freely move it around as your game needs.

    When a Character its disabled, its Move method is not called so it won't process any movement, forces, collisions, etc.

    Let me know if I can help you any further.

    Regards,
    Krull
     
    MuntyMcFly likes this.
  29. Nashnir

    Nashnir

    Joined:
    Oct 30, 2015
    Posts:
    23
    Hi I currently imported 1.2.0 (Current) and all the examples seem to be using the Old Input System.
    Is there something I missed. (I had the New Input System Installed and then Imported ECM2)
     
  30. Krull

    Krull

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

    Probably you are looking into the Character Movement folder, this includes the whole Character Movement package, this is the fully kinematic character controller (analogue to unity's built in cc).

    Take a look into the Characters folder for the high-level Characters api, built on top of the Character Movement component and using the new Input System.
     
  31. Nashnir

    Nashnir

    Joined:
    Oct 30, 2015
    Posts:
    23
    Thank you!
    I have no idea how I missed that this time.
     
  32. jimmygladfelter

    jimmygladfelter

    Joined:
    May 3, 2020
    Posts:
    83
    Hello @Krull

    I am currently working on a sonic fan game and am trying to use ECM2 but am having difficulty with having the character going around a loop-dee-loop mesh.

    I see in previous comments that I should be learning from the planet walk example. However, instead of a referenced game object like "planet", I was hoping for a more global solution such as update gravity based on current slope maybe so that character slides off of the loop if they do not have enough speed?

    I guess that also brings me to another similar question: how would I configure the controller to have like a rolling ball type of movement. For example if I'm on a slope and not moving, it steadily moves with gravity down the slope to flat ground, etc.

    Any advice would be greatly appreciated! Thanks and have a great weekend!
     
    Last edited: Apr 16, 2022
  33. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72
    I don't know for sure, but my guess for the loop thing you'd need to adjust the gravity direction based on the ground contact normal. This would probably also be applicable for the slope part, check the normal, get the angle and if ifs greater than a certain amount and there is no input then move in the direction of down the hill.
     
    jimmygladfelter likes this.
  34. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Glad I could help!
     
  35. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Yes, as @Broudy001 already commented, for a sonic like movement, you'll need to orient the character and gravity along the current ground surface normal, this way the character will be able to follow loops without issues.

    The planet walk for simplicity orient the character and gravity towards planet center, but a more general approach is using the ground surface normal.

    Let me know if can help you any further.

    Regards,
    Krull
     
    jimmygladfelter likes this.
  36. jimmygladfelter

    jimmygladfelter

    Joined:
    May 3, 2020
    Posts:
    83
    Thanks guys!

    I'm now am aligning the character to slope with this code in my controller via the suggestions and am making some progress:

    Code (CSharp):
    1. protected override void UpdateRotation()
    2.         {
    3.             base.UpdateRotation();
    4.  
    5.             // rotate based on surface normal.
    6.             Vector3 surfaceNormal = Vector3.up;
    7.             if (this.IsOnWalkableGround())
    8.             {
    9.                 // only apply surface normal if it has a magnitude (has been set due to being on ground).
    10.                 Vector3 groundSurfaceNormal = this.characterMovement.groundSurfaceNormal.normalized;
    11.                 if (!groundSurfaceNormal.isZero())
    12.                 {
    13.                     surfaceNormal = groundSurfaceNormal;
    14.                 }
    15.             }
    16.  
    17.             this.gravity = surfaceNormal * -this.gravity.magnitude;
    18.             this.characterMovement.rotation = Quaternion.FromToRotation(this.GetUpVector(), -this.gravity) * this.GetRotation();
    19.         }
    Im still fighting with the loop-dee-loop but Im starting to think its the way my input and camera are configured now so I have to look into that further. :)

    Thanks again!
     
  37. jimmygladfelter

    jimmygladfelter

    Joined:
    May 3, 2020
    Posts:
    83

    Since I'm aligning my character now to the slope via ground normal and the character stands on a slope I would like to have a gravity force pull the character down the slope again if no speed.

    Just curious what you would suggest to override in order to apply this kind of force?

    Thanks!
     
  38. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    I think you will need to update to ground normal even when on ground, not only on walkable ground, as this could prevent some movement.

    Mmm, I think (not tested) you can add a downwards gravity force when no input, this will slowly make the character to slidedown, also make sure to set the deceleration to zero, and tweak your movement with ground friction only, this will make easier to simulate different ground surfaces frictions.

    For the slidedown part, I think the most 'correct' way is compute a slide down normal, a normal perpendicular to the surface normal, pointing down slope, and apply a force along that direction. something like that.

    Is your game third or first person? I think I can setup a basic example next week (usually do not do support on weekend).

    Cheers,
    Krull
     
  39. jimmygladfelter

    jimmygladfelter

    Joined:
    May 3, 2020
    Posts:
    83
    Thanks for your suggestion. Oh and it is a third person. I am able to have the character slide down via this code now:


    Code (CSharp):
    1. protected override void Walking(Vector3 desiredVelocity)
    2.         {
    3.             base.Walking(desiredVelocity);
    4.  
    5.             // apply downward gravity force so character slides off of slope if not moving.
    6.             if (this.GetMovementDirection().isZero())
    7.             {
    8.                 // when the slope angle is above a certain threshold.
    9.                 float slopeAngle = Mathf.Abs(180f - Vector3.Angle(this.DetermineGravityFromSurfaceNormal(), Vector3.up));
    10.                 if (slopeAngle >= this.minSlopeAngleForGravity)
    11.                 {
    12.                     this.ApplySlopeGravityForce();
    13.                 }
    14.             }
    15.         }
    16.  
    17.         protected virtual Vector3 DetermineGravityFromSurfaceNormal()
    18.         {
    19.             // rotate based on surface normal.
    20.             Vector3 surfaceNormal = Vector3.up;
    21.             if (this.IsOnWalkableGround())
    22.             {
    23.                 // only apply surface normal if it has a magnitude (has been set due to being on ground).
    24.                 Vector3 groundSurfaceNormal = this.characterMovement.groundSurfaceNormal.normalized;
    25.                 if (!groundSurfaceNormal.isZero())
    26.                 {
    27.                     surfaceNormal = groundSurfaceNormal;
    28.                 }
    29.             }
    30.             return -surfaceNormal;
    31.         }
    32.  
    33.         protected virtual void ApplySlopeGravityForce()
    34.         {
    35.             Vector3 normalGravity = this.mass * Vector3.up * -this.gravity.magnitude;
    36.             this.characterMovement.AddForce(normalGravity * this.slopeGravityForceScale);
    37.         }
    I guess your saying though that a better approach would be to use a force perpendicular to slope normal instead of just downward.

    Im just not sure how to get the right direction....I guess Im not sure what to do the cross product of vectors with to get the correct slope gravity force to get it pointing down the slope.
    upload_2022-4-18_22-19-24.png
     
    Last edited: Apr 19, 2022
  40. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    ecm2-capsule.gif

    Does ECM2 have any new features that help me avoid the dreaded capsule bounce when slightly missing a jump? It's truly the worst feeling part of using this. The Flat Bottom only helps when already standing on the surface. It doesn't let me help the player get onto the ledge.
     
  41. coromo

    coromo

    Joined:
    Sep 23, 2018
    Posts:
    3
    ECM2_ThirdPersonCharacter will always run. How can I switch between walking and running?
     
  42. jimmygladfelter

    jimmygladfelter

    Joined:
    May 3, 2020
    Posts:
    83

    Here is an update on my slope angle movement, but still having trouble with the loop-dee-loop:


    But if you watch towards the end of the video, I cant get past 90degree angle when tying to go around a loop-dee-loop mesh. I tried with the example plant walk camera controller as well but the same issue happens. Any ideas on what I might be missing?
     
    Last edited: Apr 19, 2022
  43. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Actually if using latest version (Character Movement kinematic version), internally it will re-orient the character's velocity along surface normal so the down slope should not be needed, so you current ApplySlopeGravityForce function should provide same results.

    To walk along the loop you ll need to orient your character and gravity vector along the ground surface normal also since your movement is relative to yours camera's view direction, your camera should be rotated too, otherwise it won't let you walk upside down.

    Take the planet walk example, in the custom Character class, it updates the gravity towards planet's center (in your case will be the -surfaceNormal) and the character so its up-axis is aligned with the surface normal.

    The camera does a similar thing, in the custom ThirdPersonCamera class, in its update rotation, without this the upside down movement wont work.

    Also I think your angle threshold check, should use the character's up vs the world's up axis. so when a loop, the character up is the same as its surface normal so the angle is 0, like when on a flat surface.
     
    jimmygladfelter likes this.
  44. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    That's not correct, the kinematic version (since version 1.1) when use flat base is enabled, it perform full ground detection using box casts, this is exactly the same behaviour as the Unreal Engine Character Movement and offers the exactly the same results (ue users can easily test it ;))

    In your case, seems you are using a reduced perch offset, I suggest you set the perch offset to your radius size and enable use flat base for ground checks.
     
  45. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    It defaults to your current max walk speed, and only run when CanEver Sprint is enabled AND sprinting is initiated by a input (Sprint() / StopSprinting()).

    So to walk slowly, set the Max Walk Speed to 2 and setting Spring Speed Modifier to 2 will result in a max run speed (when sprinting) of 4.

    Now if using root motion, the animation velocity completely replaces the procedurally generated velocity (as it should), so to walk, you'll need to play a walk animation.
     
  46. coromo

    coromo

    Joined:
    Sep 23, 2018
    Posts:
    3
    Thank you for your reply.
    What I want to know is how can I make my character walk.
    When I set Max Walk Speed to 2, it only slows down the movement speed, but the character's movement is still in a running motion.
     
  47. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Well ECM2 do not do any animation related, or requires you to animate your character in any particular way, so you are free to animate your characters as your game needs or even use animatos from store. Included animations and animators are authored by Unity and are only for demonstration purposes.

    However, in order to keep your animation in sync with your character's movement, you need to read the character's 'state' (its current speed, is it jumping? is grounded? etc) and use this to feed your character's animator parameters or play the desired animation.

    As you can see in the Character Animator example (Easy Character Movement 2\Characters\Examples\2.- Animation\2.1.- Character Animator) it uses the data provided by the Character Movement component and the Character to update the Animator parameters, as follows:

    Code (csharp):
    1.  
    2. private void Update()
    3. {
    4.     if (_isCharacterNull)
    5.         return;
    6.  
    7.     float deltaTime = Time.deltaTime;
    8.  
    9.     // Get Character animator
    10.  
    11.     Animator animator = _character.GetAnimator();
    12.  
    13.     // Compute input move vector in local space
    14.  
    15.     Vector3 move = transform.InverseTransformDirection(_character.GetMovementDirection());
    16.  
    17.     // Update the animator parameters
    18.  
    19.     float forwardAmount = _character.useRootMotion && _character.GetRootMotionController()
    20.         ? move.z
    21.         : Mathf.InverseLerp(0.0f, _character.GetMaxSpeed(), _character.GetSpeed());
    22.  
    23.     animator.SetFloat(Forward, forwardAmount, 0.1f, deltaTime);
    24.     animator.SetFloat(Turn, Mathf.Atan2(move.x, move.z), 0.1f, deltaTime);
    25.  
    26.     animator.SetBool(Ground, _character.IsGrounded());
    27.     animator.SetBool(Crouch, _character.IsCrouching());
    28.  
    29.     if (_character.IsFalling())
    30.         animator.SetFloat(Jump, _character.GetVelocity().y, 0.1f, deltaTime);
    31.  
    32.     // Calculate which leg is behind, so as to leave that leg trailing in the jump animation
    33.     // (This code is reliant on the specific run cycle offset in our animations,
    34.     // and assumes one leg passes the other at the normalized clip times of 0.0 and 0.5)
    35.  
    36.     float runCycle = Mathf.Repeat(animator.GetCurrentAnimatorStateInfo(0).normalizedTime + 0.2f, 1.0f);
    37.     float jumpLeg = (runCycle < 0.5f ? 1.0f : -1.0f) * forwardAmount;
    38.  
    39.     if (_character.IsGrounded())
    40.         animator.SetFloat(JumpLeg, jumpLeg);
    41. }
    42.  
    The included animator blends from walk to run based on the input, like many modern games.

    In your case, your character needs a walking animation and when running (i.e. a key is pressed) transition to the running animation.
     
  48. Krull

    Krull

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

    I created a basic example showing the orient along ground normal. It orient the camera by default however this is only really needed for the loop movement as the movement is relative to camera view direction, otherwise the character
    won't walk upside down.

    To use this, simply import into a Unity project with ecm2 installed on it.
     

    Attached Files:

    jimmygladfelter likes this.
  49. jimmygladfelter

    jimmygladfelter

    Joined:
    May 3, 2020
    Posts:
    83
    Thanks for the tips! After reviewing the planet walk example, it is indeed the camera rotation I was lacking to complete the loop. Appreciate your hard work on this controller. It's awesome!
     
  50. jimmygladfelter

    jimmygladfelter

    Joined:
    May 3, 2020
    Posts:
    83
    Oh I didn't even see this I'll take a look when I get the chance thanks!