Search Unity

[RELEASED] Easy Character Movement

Discussion in 'Assets and Asset Store' started by Krull, Apr 21, 2016.

  1. ShiftedClock

    ShiftedClock

    Joined:
    Sep 12, 2012
    Posts:
    18
    Thanks for the fast reply and updated manual, very impressive.

    Does this warning popup because the ProjectSettings directory is included? If so, it might be helpful to remove it from the asset.
     
  2. net8floz

    net8floz

    Joined:
    Oct 21, 2017
    Posts:
    37
    I'm not sure in what situation including random project settings would be desired I found this confusing. Is this a common asset practice?
     
  3. VincentAbert

    VincentAbert

    Joined:
    May 2, 2020
    Posts:
    123
    Hello @Krull !

    Thanks a lot for the great asset :) I just got it and thus decided to adapt my current controller using it, so far so good (the examples are a huge help) but I have a question : what would be the preferred way of just setting the character's position in world space ? Is using 'transform.position =' fine, or would that leave some problems ? Thanks again !

    EDIT : Just to make things clearer, here is my current problem : when the character jumps and encounters a ledge, I want her to hang on to it, which I used to do by just lerping her position to the ledge. but right now your controller is taking her velocity into account, which means she keeps moving for a while (I used the allow vertical bool to switch to the hanging state). I guess I just a want a way to disable physics for a while and take full control.

    EDIT 2 : I found the Pause method in the movement script which is pretty much what I was looking for, so that's great, but now I have another question : how would I go about dynamically switching root motion on and off ? Because it seems quite the complex set up (with the component, the different bools etc.), and I'd like to just switch to root motion for one animation and then just switch back (I used to just use a state machine behaviour that would change my animator bool)
    Thanks a lot
     
    Last edited: Sep 13, 2020
  4. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hello @ShiftedClock and @net8floz

    About the project settings, those are included as part of the process while submitting it to the Unity Asset Store, unity add those by default as the package is listed on the store as a complete project, the only way to remove those is listing it on a different category on the asset store.

    I have planned for next version to list it on a different category so it will solve the settings issue.

    Regards,
    Krull
     
    ShiftedClock likes this.
  5. Krull

    Krull

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

    Glad you solved your previous issues, and yes pausing it basically turns the character into a Kiniematic Rigidbody so you can move modifying its position if needed.

    About the root motion, you can toggle it using the BaseCharacterController useRootMotion property as needed, however worth note that by default ECM will disable RootMotion when character is not grounded, however this can easily be modified in your custom controller if needed.

    Let me know if need further help.

    Best regards,
    Krull
     
  6. VincentAbert

    VincentAbert

    Joined:
    May 2, 2020
    Posts:
    123
    Thanks for the answer ! I've tried a few things but I can't manage to use root motion in my situation, which is the following :
    when my character is hanging under a ledge, I want to trigger her 'getting on top of the ledge animation', which is controlled by root motion. With my old controller, all I had to do was to set the Animator apply root motion to true, and back to false. Now I have tried to set the controller userootmotion and applyrootmotion to true (not sure what the difference is btw, should I set both of them ?), tried to pause the movement script, tried to set the animator directly, but the animation doesn't use root motion... I thought it might be because of the not grounded state, as you just mentionned the controller would then ignore root motion, but I tried to comment out the "&& movement.isgrounded" part of the base controller, just for testing, and still had the same problem...

    Also, I noticed that using "(movement.isgrounded && !movement.wasgrounded)" to check wether the character just landed is a bit unreliable : every once in a while she will stay in her jumping state despite landing. Any idea where this might come from ?
     
  7. Krull

    Krull

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

    I understand your confusion about the useRootmotion and applyRootmotion properties, it works as follows:

    ECM allow the toggle of root motion velocity or physics velocity, as you can see in the demos, you can press the R key to toggle between root motion based movement or physics based movement.

    In order to enable root motion based movement you need to set the BaseCharacterController useRootMotion proptery to true.

    While using Root tMotion (useRootMotion == true) ECM will simply pass the root motion velocity to the CharacterMovement Move method as the animation will take full control of how to move the character. However by default ECM will only apply the root motion movement when the character is grounded, (as you can see in the BaseCharacterController Move method) and this is controlled by the applyRootMotion property.

    This is needed in order to disable the root motion movement to allow the character to perform the jump, fall, etc. This can easily be modified to match your game needs, overriding the Move method in you custom controller, and modify it to match your game needs.

    Code (csharp):
    1.  
    2. protected virtual void Move()
    3. {
    4.     // Apply movement
    5.  
    6.     // If using root motion and root motion is being applied (eg: grounded),
    7.     // move without acceleration / deceleration, let the animation takes full control
    8.  
    9.     var desiredVelocity = CalcDesiredVelocity();
    10.  
    11.     if (useRootMotion && applyRootMotion)
    12.         movement.Move(desiredVelocity, speed, !allowVerticalMovement);
    13.     else
    14.     {
    15.         // Move with acceleration and friction
    16.  
    17.         var currentFriction = isGrounded ? groundFriction : airFriction;
    18.         var currentBrakingFriction = useBrakingFriction ? brakingFriction : currentFriction;
    19.  
    20.         movement.Move(desiredVelocity, speed, acceleration, deceleration, currentFriction,
    21.             currentBrakingFriction, !allowVerticalMovement);
    22.     }
    23.  
    24.     // Jump logic
    25.  
    26.     Jump();
    27.     MidAirJump();
    28.     UpdateJumpTimer();
    29.  
    30.     // Update root motion state,
    31.     // should animator root motion be enabled? (eg: is grounded)
    32.  
    33.     applyRootMotion = useRootMotion && movement.isGrounded;
    34. }
    35.  
    As you can see in the above code, the root motion movement will only be applied when you enabled it (useRootMotion == true) and the character's state is grounded.

    About the landing state check, this is a reliable way to check it, if it is falling could be because of a 'desync' of the character's grounding state, causing its state not be up to date when you check the condition.

    In order to better help you, I appreciate if could contact me to support email, and if possible provide me a basic scene with your current issue, Ill be happy to take a look at it and find the causes of your current issues.

    Regards,
    Oscar
     
    CanardCoinCoin likes this.
  8. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Hi, my project is using unity's new input system and seems that many errors are popping up.
    Is it possible to add support for unity's new input system.
     
  9. Krull

    Krull

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

    Well, while ECM uses the default Unity Input system (the old one), ECM is not really tied to it and can be easily modified to support the new Input System.

    To acomplish this, in your custom controller, override its HandleInput method and add new Input code in there, for example:

    Code (csharp):
    1.  
    2. protected override void HandleInput()
    3. {
    4.     // Default ECM Input as used in BaseCharacterController HandleInput method.
    5.     // Replace this with your custom input code here...
    6.  
    7.     //
    8.     // For example, you can replace the above code to use the Unity NEW Input system as follows
    9.  
    10.     var gamepad = Gamepad.current;
    11.     if (gamepad == null)
    12.         return; // No gamepad connected.
    13.  
    14.     moveDirection = gamepad.leftStick.ReadValue();
    15.  
    16.     //... Add gamepad button inputs here
    17.     //etc...
    18. }
    19.  
    However worth note, the examples and other controllers will use old input system, so I suggest enable 'both' systems to avoid errors, and use the New Input System to develop your game following the above pattern.

    Regards,
    Krull
     
  10. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    I was trying to implement a spring/bouncer object that propelled the character into the air without control for a short while. How do you recommend I do this? Adding directly to the rigidbody didn't seem to work well.
     
  11. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    605
    Are you planning to add ledge hanging to future editions, or should I look elsewhere for something like this?
    It makes a huge difference to older games like Mario 64.

    There's a great example of ledge hanging here
    https://www.patreon.com/posts/moving-kat-3-32716107
     
  12. Krull

    Krull

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

    About your questions:
    The best way to handle this is treat it like a jump, on your spring apply a jump impulse, however just like the jump, you need to tell the character is allowed to leave the ground, using the movement.DisableGrounding() otherwise the character will be pulled back to ground.

    Additionally, just like the jump (its variable height part), you can keep adding a light force or even reduce the gravity, or set the max fall speed to a low value, to ease the character falling.


    Thank you for sharing the link info, interesting! unfortunately I do not have planned to add it to the upcoming ECM version, as my main goal with ECM is to serve as a general purpose character controller where users can build its game mechanics on top of the existing ECM functionality.

    While I really can not promise it, if added some kind of climbing system, it would be as an optional add-on and no part of ECM, mostly because of above reasons.

    Regards,
    Oscar
     
  13. WryMim

    WryMim

    Joined:
    Mar 16, 2019
    Posts:
    69
    Thanks for the miracle asset!

    Need help.

    When I press the "throw" button, I need the player to turn towards the camera. What's the best way to do this?

    That is, not a rotation through X Y from the mouse. A method like Rotate (targetDirection) and the player turns there.
     
  14. craigjwhitmore

    craigjwhitmore

    Joined:
    Apr 15, 2018
    Posts:
    135
    Root motion doesn't seem to work with this at all. The Demo scene (Custom Character Controller) doesn't switch between walk and run, the character constantly slides for both cases. The sliding is particularly evident if Walk Speed is set to 0.5 and Runspeed set to 1. Even with these settings, the animator parameter for forward speed remains at 0.999, causing the run animation to play despite being in walk.

    The Use Root Motion check box is true.
     
  15. Krull

    Krull

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

    Thank you :)

    About your question, the BaseCharacterController includes several helper functions to rotate the character:
    Code (csharp):
    1. /// <summary>
    2. /// Rotate the character towards a given direction vector.
    3. /// </summary>
    4. /// <param name="direction">The target direction</param>
    5. /// <param name="onlyLateral">Should it be restricted to XZ only?</param>
    6.  
    7. public void RotateTowards(Vector3 direction, bool onlyLateral = true)
    8.  
    9. /// <summary>
    10. /// Rotate the character towards move direction vector (input).
    11. /// </summary>
    12. /// <param name="onlyLateral">Should it be restricted to XZ only?</param>
    13.  
    14. public void RotateTowardsMoveDirection(bool onlyLateral = true)
    15.  
    16. /// <summary>
    17. /// Rotate the character towards its velocity vector.
    18. /// </summary>
    19. /// <param name="onlyLateral">Should it be restricted to XZ only?</param>
    20.  
    21. public void RotateTowardsVelocity(bool onlyLateral = true)
    In your case you could use the RotateTowards method, worth note by default an ECM character will rotate towards its current input move direction (BaseCharacterController UpdateRotation method), so in your custom controller, you can modify this method to rotate towards a given direction.

    Regards,
    Krull
     
    WryMim likes this.
  16. Krull

    Krull

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

    About your question, yes the CustomCharacterController example does not change the animation based on character's speed when using root motion, however this can easily be modified as follows:

    In the CustomCharactercontroller Animate method, simply replace the line at 114:
    Code (csharp):
    1. // Update the animator parameters
    2.  
    3. var forwardAmount = animator.applyRootMotion
    4.     ? move.z
    5.     : Mathf.InverseLerp(0.0f, runSpeed, movement.forwardSpeed);
    with the following:
    Code (csharp):
    1.  
    2. var forwardAmount = animator.applyRootMotion
    3.     ? Mathf.InverseLerp(0.0f, runSpeed, move.z * speed)
    4.     : Mathf.InverseLerp(0.0f, runSpeed, movement.forwardSpeed);
    5.  
    this will enable walk / run with root motion as it does without root motion.

    Regards,
    Krull
     
  17. Pandur1982

    Pandur1982

    Joined:
    Jun 16, 2015
    Posts:
    275
    Hello i have a question, how can i make Swimming with that Controller? I have take a Look in the documentation but i found not or iam blind. And the same for climbing a Lader. And a other question for the third person Controller how i can activate that the Controller will strafe and not lean and walk in a circle.
     
  18. craigjwhitmore

    craigjwhitmore

    Joined:
    Apr 15, 2018
    Posts:
    135
    That does change the animation between walk & run. Root motion still doesn't work. Just set walk speed to 0.5 and run to 1 and it'll be obvious.
     
  19. Krull

    Krull

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

    You can find the additional examples on the Walkthrough section, it includes many additional examples. About the ladder climbing example, its been released after the update so its not included in current 1.8 version, however you can find it here

    Regards,
    Krull
     
  20. Krull

    Krull

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

    Well with root motion basically you are controlling the animation with input, which in turn gives the desired movement velocity.

    The example works as commented above, however it still will clamp the given desiredVelocity to the speed property value as you can see in the BaseCharacterController Move method, so if using root motion, just set the speed property to your current animation speed value or just set it to a high value so the animation speed does not get clamped.

    Having said that, If your game is using mostly root motion, I suggest you override the Move method in you custom controller and modify it to match your game needs.

    Cheers,
    Krull
     
  21. valmyr

    valmyr

    Joined:
    Jan 31, 2018
    Posts:
    23
    Hi Krull!! This is a great asset! I like it. Just want to ask if you have plans to add a camera system? Seems like it is the only thing missing especially when using it in third person view. It would be great if it would have something that can focus on the player and avoid the obstacles/clipping.
     
  22. WryMim

    WryMim

    Joined:
    Mar 16, 2019
    Posts:
    69
    Hey. I just wanted to give my opinion.
    There is also a free asset in Unity Cinemachine, there you can make any version of the camera.
     
    Krull likes this.
  23. Krull

    Krull

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

    About your question, well I do not have planned to add a full featured camera component to ECM mainly because I would like to keep it focused on character controller, and there are many good camera solutions available which works with ECM.

    Having said that, what I have planned to add in future updates is as @WryMim said, include an example of how to integrate Unity Cinemachine with ECM.

    Regards,
    Krull
     
    Willbkool_FPCS likes this.
  24. valmyr

    valmyr

    Joined:
    Jan 31, 2018
    Posts:
    23
    Hi @Krull,

    Thank you for considering cinemachine. I understand the focus on character controller. I'm just thinking that It will be a good supplement for the movements especially for third person view. To have something that we can use as a base is better instead of making our own version of the camera.

    By the way here is a screenshot from the demo. Was wondering why is it setup like this by default?

    upload_2020-10-4_17-15-4.png

    I searched the manual and looked at the code and saw that these properties are public. But I'm just wondering also why I cannot see them in the inspector.

    isOnLedgeEmptySide
    isOnLedgeSolidSide

    When I switch to Debug in the inspector, I can see some properties like
    'isOnPlatform' but not all the other properties declared public.

    Regards,
    Rain
     
  25. khushalkhan

    khushalkhan

    Joined:
    Aug 6, 2016
    Posts:
    177
    It is great package, but just movement is not enough let's see if you can add melee or shooter etc logic to controller
     
  26. Krull

    Krull

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

    Well I could add it as an example, actually it includes an over shoulder example camera system example, and definitely should help you to get started with a third person like movement, you can find it in the walkthrough example # 13.

    The picture is using a ledgeOffset of 0.3 (capsule radius), this property is the maximum distance from the ledge (measured as the horizontal distance from the character's position to ledge hit point) a character can stand without falling, you can set it to 0, and it will fall when a ledge if found.

    Yes, those are properties, not fields and those properties are not shown in editor, well it can but need a custom editor to show those. Those properties are computed properties and are the result of the ground detection evaluation, think of those as a report of where the character is standing on.

    You can 'see' those if enable gizmos on your scene and keep selected your ECM character, when selected it will show its debug aid gizmos, in the above case, it will show a green circle at the character's foot position, showing its ledgeOffset radius.

    For example the gizmos will also show if character is grounded (green bottom sphere), red bottom sphere if not grounded etc.

    regards,
    Krull
     
  27. Krull

    Krull

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

    Thank you for your suggestion, however the main goal with ECM is to serve as a general purpose character controller, where users can build its game specific mechanics on top the default ECM functionality.

    Having said that I could consider developing some add-ons including those kind of mechanics without altering the main goal of ECM, a clean, lean a feature reach character controller to serve as a base for your game mechanics.

    Cheers,
    Krull
     
  28. SaeedPrez

    SaeedPrez

    Joined:
    May 10, 2017
    Posts:
    6
    Hi,

    I recently bought your asset and I'm trying to replace my current movement script, but I've ran into an issue.

    I have a character and ground tiles that push the player in a specific direction when standing on them (like a treadmill). To add the extra movement from the tiles I have overridden the CalcDesiredVelocity() method like this:

    Code (CSharp):
    1.     protected override Vector3 CalcDesiredVelocity()
    2.     {
    3.         var desiredVelocity = base.CalcDesiredVelocity();
    4.         desiredVelocity += this.extraMovement;
    5.  
    6.         return desiredVelocity;
    7.     }
    Let's assume the player's movement speed is 6 and the tiles push with 5 speed.

    When the player doesn't move, the player gets pushed as expected.

    When the player moves opposite the tile direction (6 - 5 = 1 movement speed), the player moves slowly in the opposite direction of the tiles just as expected.

    The problem is when I move in the tile direction (6 + 5 = 11 movement speed), the player moves like normal (6 movement speed). I have tried setting the literal speed to 20 and even higher but nothing seems to work.



    I have tried applying different types of forces and whatnot, but nothing gives the desired effect.

    Any idea how I can fix this?

    Edit:
    After some more testing, it seems the script clamps the speed to 6 which I have defined as movement speed in the inspector. So the question is how can I add external forces and go past the speed limit? At first I thought the actual speed limit was the mat lateral speed settings?

    Edit2:
    I found a way to make it work, I set the speed to 11 and then limit the speed from from the input to maximum 6. This way I can add extra speed up to 11.
     
    Last edited: Oct 11, 2020
  29. cursedtoast

    cursedtoast

    Joined:
    Apr 27, 2018
    Posts:
    62
    Is there any sort of crouch speed I'm missing by chance? Or is that something I should override and implement myself?

    For now, I just did an override of GetTargetSpeed from BaseFirstPersonController:

    Code (CSharp):
    1. protected override float GetTargetSpeed()
    2.         {
    3.             // Defaults to forward speed
    4.  
    5.             var targetSpeed = forwardSpeed;
    6.  
    7.             // Strafe
    8.  
    9.             if (moveDirection.x > 0.0f || moveDirection.x < 0.0f)
    10.                 targetSpeed = strafeSpeed;
    11.  
    12.             // Backwards
    13.  
    14.             if (moveDirection.z < 0.0f)
    15.                 targetSpeed = backwardSpeed;
    16.  
    17.             // Forward handled last as if strafing and moving forward at the same time,
    18.             // forward speed should take precedence
    19.  
    20.             if (moveDirection.z > 0.0f)
    21.                 targetSpeed = forwardSpeed;
    22.          
    23.          
    24.             // Crouch speed *** This part is custom ***
    25.             if (crouch)
    26.             {
    27.                 targetSpeed = (forwardSpeed / _crouchSpeedModifier);
    28.             }
    29.  
    30. // Handle run speed modifier
    31.  
    32.             return run ? targetSpeed * runSpeedMultiplier : targetSpeed;
    33.         }
    Though, I just realized I'll need another check to see if crouched before returning the modified speed factoring in running.
     
    Last edited: Oct 12, 2020
  30. Krull

    Krull

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

    About your question, yes your approach is correct, as you noticed the given desiredVelocity returned in the CalcDesiredVelocity method, will still be clamped to the current speed property value, think of this speed property as the character's current state max speed.

    Another way you could handle this, is using external forces, I mean just apply a force (velocity change, impulse, etc), and this force act on the character unclamped by the desired, after all its just a rigidbody acting as a character.

    Regards,
    Krull
     
  31. Krull

    Krull

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

    Yes, by default it does not modify the character's speed while crouched, so no crouched speed property available. Your solution is correct, the idea is set the character's speed property to your character's current state max speed, as the above post, the speed property is actually our character's current state max speed value (should have named it maxSpeed :)).

    You can check if the character's is currently crouching using the CharacterBaseController isCrounching property. You can see a working example in the walkthrough example # 5 where we use the isCrouching property to animate the camera to perform the crouching animation.

    Regards,
    Krull
     
    cursedtoast likes this.
  32. my_little_kafka

    my_little_kafka

    Joined:
    Feb 6, 2014
    Posts:
    87
    Hello again!
    I really enjoy the asset, and I was able to simply change standard Unity's CharacterController to ECM components in order to my character controller to work again (of course I had to make small changes here and there and tweak the speeds). I noticed a small problem - if the Snap to Ground parameter in CharacterMovement is turned on, randomly the rigidbody's speed value will be freezed, even when I don't move the PlayerCharacter:
    upload_2020-10-13_15-48-44.png

    When it's "stuck", the speed is always equals to the Velocity's Y value. Another strange thing is that simply moving the camera with a mouse makes the speed of a rigidbody to fluctuate. I rewrote my CameraController script so it will change the rotation through the rigidbody, like in your implementation of a FirstPersonCharacter, and I think I did everything right - but even if I disable the mouse look, the speed still gets stuck sometimes (not always) simply by moving. If I disable the Snap to Ground parameter, everything seems to work fine. How important it is? Does it work the best with very fast characters? I don't notice any differences with it being turned on and off while running the example scenes.
    I don't use the base classes provided, but I went through the code (which is very a good experience, the code is very clear and easy to navigate) and simply converted my own CharacterController to ECM. Maybe I missed something important? The coordinates are
    Could this be because the code of my CharacterController doesn't call to FixedUpdate directly, but it catches a FixedUpdate event from a controller script (so I basically chain a lot of objects which control other objects, with the top object using actual Start, Update and FixedUpdate events which are being sent to the hierarchy)?
    If the ground snapping is not viable for ordinary moving characters, I would simply turn it off, as it seemingly works just fine, but I want to know if it's important to the whole collision system.
     
  33. Krull

    Krull

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

    About your issue, I think it is related to the snap to ground used 1.8 version, it is position based (vs the previous velocity based), so even if your character is standing stills (no input velocity), the snap to ground will still pulling him back to ground, thats the tiny velocity in Y you noticed, however I noticed this snap to ground method could cause issues in some circunstances, so I decided to roll back to the velocity based method which is more flexible.

    I just finishing some minor bug fixes (in example scenes), before release it.

    Kind regards,
    Krull
     
    my_little_kafka likes this.
  34. dmarqs

    dmarqs

    Joined:
    Oct 16, 2013
    Posts:
    41
    HI,

    I'm really in love with ECM until now. =)

    Everything seems to work as expected.

    2 questions:

    1 - There is support for 'planet walk' like in Mario Galaxy?

    2 - I would like to avoid my character to fall off ledges, like if there is an invisible wall. Is there anyway I can verify if player is in front of a ledge and don't let him fall? Even that I had to add an invisible wall dynamically.

    Thanks! =D
     
  35. Krull

    Krull

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

    About your questions:

    Absolutely, however not out of the box. The latest ECM update added support to rotate the character, previously was required to remain upright all time.

    The idea is to query the current surface normal, and align / rotate the character to follow the terrain contour, however its also necesary to align the gravity. You can check a similar approach in the included walkthrough example 8 - Orient Towards Ground Normals as it uses a similar approach.

    You can use the info provided by the CharacterMovement component (accessed in controller with movement property), this reports a lot of information about the 'ground' where character is currently standing on, for example: movement.isOnLedgeSolidSide, movement.isOnLedgeEmptySide, movement.ledgeDistance

    A rough approach is to downcast a fixed distance in front of your character, and if no 'ground' found, prevent its movement along its current direction.

    Kind regards,
    Krull
     
  36. YorkshirePudding

    YorkshirePudding

    Joined:
    Apr 10, 2013
    Posts:
    18
    Hi All @Krull ,

    I wondered if you could help me. I have the character controller setup and working fine, however, I have one problem. When the character jumps I play a jump animation (no root motion) but when the character lands it is off the ground (see attachment). If I drag the character down using the scene tools (in play mode) it sits back on the floor fine.

    I really can't figure this one out, as a test I removed the jump animation and it seems to work fine, is there a setting or something I need to use to tell the controller to not pay any attention to the animations? I have setup my model as a child of the character controller as per the documentation.

    My character is using a derived class of the BaseController which changes/overrides nothing other than the HandleInput and Animate methods.

    Thank you in advance for any help.

    Screenshot 2020-10-26 at 22.21.17.png
     
  37. Krull

    Krull

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

    Your issue seems to be related to the ground snap feature, as the animations are 'cosmetic' only, I mean, the CharacterMovement do not read or use it in any way, actually is the other way, where you use the information provied y the CharacterMovement controller (eg: isGrounded, velocity, etc), to drive your animations.

    Please take a look at the following settings which definitely could cause this issue.

    First, check if your character collider's center is correctly configured, it must be your heght / 2.0f, for example:
    A default 2 units tall character:

    center: 0, 1, 0
    radius: 0.5
    height: 2

    In the GroundDetection component, make sure your cast distance is at least your capsule's radius and your ground layer is part of the GroundMask, otherwise it wont see the 'ground'.

    Last but not least, in the CharacterMovement component, make sure the snap to ground is enabled.

    Please do not hesitate to message me back, if need any further help.

    Regards,
    Krull
     
  38. s0lt4r

    s0lt4r

    Joined:
    Jun 9, 2015
    Posts:
    13
    @Arkade @Krull were either of you able to get A* working for for ECM? I'm having a hard time wrapping my head around the process.
     
  39. YorkshirePudding

    YorkshirePudding

    Joined:
    Apr 10, 2013
    Posts:
    18
    Hi @Krull,

    Firstly, thank you for your reply and tips.

    I changed the Cast Distance to 0.1 above the radius (to be sure) and enabled Snap to Ground, my character is now aligning with the ground perfectly after a jump. Thank you very much.

    Great asset by the way
     
  40. Amo-deus

    Amo-deus

    Joined:
    Jul 27, 2015
    Posts:
    25
    Is there a function to detect if the player is standing on flat ground but also against a slope? I'm having some slope animation jitter problems where the controller is confused about whether I should be sliding or walking or pushing against a wall
     

    Attached Files:

  41. Krull

    Krull

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

    Being honest I am really not familiar with the A* (I assume you reffer to A* Pathfinding Project) so I really cant help much regarding this integration atm.

    Having said that ECM includes support for Unity NavMesh Agent (BaseAgentController) and I think this should help you to understand how to move the character using an AI to calculate our desired direction.

    By other hand, as this is a common request I have planned to add an example of how to use ECM with it, in following updates (1.8.2).

    Kind regards,
    Krull
     
  42. Krull

    Krull

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

    Thats great! thanks for the update and glad I could help you!

    Regards,
    Krull
     
    Last edited: Oct 31, 2020
  43. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Hi @Amodeus-S

    You can use the groundAngle (eg: movement.groundAngle) along the extensive ground information provided by the CharacterMovement component in order to detect where is your character currently standing on, for example:

    Code (csharp):
    1.  
    2. public bool isOnFlatGround
    3. {
    4.     get { return Mathf.Approximately(movement.groundAngle, 0.0f); }
    5. }
    6.  
    This property check if the ground angle is ~0 the character is on flat ground.

    About the issue you are having, well this is 'eased' at most as this ECM version does not look ahead, at great sight, it just detects where is the character's standing on and decides how to project / modify its velocity in oder to move, the good news is that I have been working on a new ECM version, which completely solves your current issue and greatly improves the current ECM version!

    Best regards,
    Krull
     
  44. Amo-deus

    Amo-deus

    Joined:
    Jul 27, 2015
    Posts:
    25
    Ah ok sounds awesome! I was thinking that using multiple ray casts would work but that seems expensive. I was just hoping that I didn't miss something in the code. Any word on when that will be available?
     
  45. s0lt4r

    s0lt4r

    Joined:
    Jun 9, 2015
    Posts:
    13
    Thanks @Krull I suppose, at a higher level, I'm unsure of how to have agents handle input for the character controller rather than controlling it directly. All of the examples on Aron Granberg's website rely on the movement and pathfinding being handled by the same components.
     
  46. marcos

    marcos

    Joined:
    Oct 18, 2009
    Posts:
    592
    Hello,

    Been quietly using ECM for over a year now, it's so good.

    Quick question, how do I get the character to retain the force of a moving platform when I jump?

    Also, is there a neat way to allow for the character to be affected by CharacterMovement.ApplyImpulse(v3)??

    It seems my underlying character movement is overriding the ability to have these impulses launch my character to the side:
    Code (CSharp):
    1. character.Move(desiredMove, maxSpeed, true);
    2.  
    It works vertically as I have lateral only marked true, but yeah, would be great to have a sort of physics layer over the top of the movement. I'm sure it's possible, I'm just so deep into this project now I forgot where I broke that element.

    Kindest,
    Mark
     
    Amo-deus likes this.
  47. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    About the new version, I think it will be released in about two months, as this is not a regular ECM update, its basically a completely new product built from scratch, and without fully disclosing its features, as previously commented, it greatly improves ECM.

    I have planned to release some demos before its release time, so youll be able to try it before its release date.

    Regards,
    Krull
     
    Amo-deus likes this.
  48. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    771
    Well the approach while working with ECM is create a custom controller, extending one of the included 'base' controller, and build your game mechanics on top of the given ECM functionality.

    For example, in your case if your character's needs support for AI, you create your custom controller extending the BaseAgentController as this already includes support for NavMeshAgent and implements a basic click-to-move mechanics.

    In this custom controller you modify its methods in order to fit it to match your game needs, for example, you can modify
    the HandleInput method to modify the default mouse input method.

    Actually the BaseAgentController is extending the BaseCharacterController adding support for NavMeshAgent. Its implementation its strightforward and at great sight works as follows:

    In the HandleInput method we process the input mouse click and if clicked over a valid destination, we assign the agent's destination.

    Then in the CalcDesiredVelocity method we use agent's desiredVelocity (if have a path) to compute our desired velocity (SetMoveDirection method), is this desiredVelocity (the one given by CalcDesiredVelocity method) the one we feed into the CharacterMovement Move method, which in turn will move the ECM character.

    I suggest you take a look at the included BaseAgentController, its fully commented and will definitely help you to get a clearer image of how it works.

    Kind Regards,
    Krull
     
  49. Krull

    Krull

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

    Thank you for purchasing ECM and happy to know you like it and are a long time user!

    By default it works out of box, however, this only works if using the friction based CharacterMovement Move method

    Code (csharp):
    1.  
    2. public void Move(Vector3 desiredVelocity, float maxDesiredSpeed, float acceleration, float deceleration,
    3. float friction, float brakingFriction, bool onlyLateral = true)
    4.  

    As the second Move method (the one you are using), performs an instant change in the character's velocity to match the given desired velocity, so the character's looses the platfrom's momentum.

    Actually this Move method exists because its mainly used by root motion, to pass the animation's velocity directly without it being affected by the aceleration / deceleration, friction settings.

    If possible I suggest you try the friction based Move method, and tweak its acceleration, deceleration and friction settings to tailor your desired movement.

    Regards,
    Krull
     
  50. marcos

    marcos

    Joined:
    Oct 18, 2009
    Posts:
    592
    Thank you! Turns out it was my friction being too high that stopped that method from working when I tried. Thanks again!
     
    Krull likes this.