Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

[RELEASE] Easy Character Movement 2

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

  1. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Yes, as @Broudy001 already commented when you want to leave the ground you need to explicitly tell

    Here you can temporary disable the ground constraint using the Character PauseGroundConstraint method, e.g:
    Code (csharp):
    1. PauseGroundConstraint();
    Another alternative is to set the Character movement mode to Flying, this will permanently disable ground constraint until you switch it back to walking / falling.

    Worth note the Flying movement mode will disable gravity.

    Regards,
    Krull
     
    ml785 likes this.
  2. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    48
    @Krull
    I'm looking to add Pivot Turns, and was trying to play the animation based on the change in direction of 135 degrees or more. What is the best way to get the previous direction and compare with the current one?
     
  3. Krull

    Krull

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

    You can compare the angle between the character's velocity and the current input move direction vector, if this is greater than a threshold the character did a quick turn.

    A simple dot product could work, for example:

    Code (csharp):
    1.  
    2. var speed =GetSpeed()
    3. if (speed > speedThreshold)
    4. {
    5.     if (Vector3.Dot(GetVelocity(), GetMovementDirection()) < 0.0f)
    6.     {
    7.         // velocity and move direction are completely opposite!
    8.     }
    9. }
    10.  
    Regards,
    Krull
     
  4. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    48
    Ah
    Ah nice, I'll give that a go tonight, thanks heaps
     
    Krull likes this.
  5. baumxyz

    baumxyz

    Joined:
    Mar 31, 2017
    Posts:
    55
    Hey @Krull, any idea how to get platforms that move via the "DOTween animation" script to work smoothly with ECM2? Vertically moving platforms result in the ECM character not being grounded sometimes. Is there a way to make the character stick to the surface?
     
  6. Krull

    Krull

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

    Make sure your platforms extends PlatformMovement class and update its position on its OnMove method (User manual page 48).

    Additionally make sure DOTween animates on physics or something similar as honestly not quite familiar with it.

    Regards,
    Krull
     
    baumxyz likes this.
  7. Predulus

    Predulus

    Joined:
    Feb 5, 2018
    Posts:
    19
    Hi Krull,

    I'm just starting a project which I think will be a Metroidvanian, so of course there will be ability upgrades which will change movement modes, with things like dashes, extra-high jumps, teleporting, etc.

    Any suggestions on how to handle the movement side of things? Something to point me in the right direction would be much appreciated :)

    Thanks
    Pred
     
  8. AqueductGames

    AqueductGames

    Joined:
    Dec 18, 2018
    Posts:
    1
    Hey @Krull,

    I've been using the asset for a few days now (It's great by the way) and I was wondering how I can make it so the Agent Character only moves through code. To be more precise, I want to disable the keyboard / mouse input on the character. How can I achieve that? I tried setting the movement mode to none but that just disables movement altogether.
     
  9. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    48
    You should be able to set no input action asset
     
    Krull likes this.
  10. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hey @Predulus

    The suggested method here is create a custom character class extending the Character class, and use this custom character to add your game specific mechanics like ladder climb, dash, roll, etc. . Pretty much like the included examples do. So in the end this custom character class will contain all your character actions.

    After all the main goal with ECM2 is to serve you as a platform where you can build your game specific mechanics on top of it.
     
  11. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hi @StudioAqueduct

    Yes, as @Broudy001 already commented, if you leave the Character actions property empty (no input actions asset assigned) it will not process any input, so you will be able to use its MoveToLocation method to Issue the CharacterAgent to move to a desired location
     
  12. Lekonia

    Lekonia

    Joined:
    Sep 18, 2019
    Posts:
    3
    Hey All
    I wanted to say how grateful i am for this pack, i bought and have been using it in my projects and it works wonders, thank you =)

    I do have a question about remapping or replacing the default character with characters i have acquired (Synty Charactes as an example), i tried looking throught he documentation and nothing jumped out, is there a thread here or a tutorial out there in which i can follow to see how i can manage replacing the default character and animating it?
    Any information would be appreciated, thank you =)
     
  13. Garganturod

    Garganturod

    Joined:
    May 19, 2021
    Posts:
    4
    Hello!

    I would like to have a Transform (any kind) out in front of my Character. I would like to combine the position of that Transform along with the Velocity of my Character. The goal is to make the Transform be farther away from the Character while moving, but stop and be under the Character when there is no movement. So, as the Character accelerates, the Transform would move farther way. Also, the Transform needs to follow the contour of the ground.

    It would be like a person with bad eyesight using a cane to feel in front of them. They might move the cane out farther away in front of them depending on how fast they had to move/run. When they are standing still then the cane would just be stationary.

    EMC2 is doing a ton of stuff. Before I start doing extra ray casts, etc., I was wondering if ECM2 was already doing something similar to this functionality for its movement. Maybe I can hook into some Get() methods, or make some fields public, etc.

    I'd rather not do extra checks and also use the code of someone who is good at math :)

    Thanks!
     
  14. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hi @Lekonia

    Thank you for sharing your impressions, happy to know you like it! :D

    About your question, well with ECM2 you are not forced to animate your character in a special way, so you can use the models / animations you prefer using the plain Unity way.

    The idea is to use the information provided by an ECM2 Character to feed your animator, such as if the character is grounded, its movement direction, its speed, etc.

    As you can see in the included UnityCharacterAnimator example script, we just read the character state and feed this to the character animator controller.

    Alternatively if extending a Character you can override its Animate method, and feed your animator in there, but once again is not mandatory and can be animated from an external script, like the included example.

    Regards,
    Krull
     
    JohnnyGo-Time likes this.
  15. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hi @Garganturod,

    About your question:

    To get a position in front of the character, you simply use:

    Code (csharp):
    1. GetPosition() + GetForwardVector()
    However this forward vector is just the character's heading position BUT not follows contour, so you will need to project it along character's current ground information, e.g:

    Code (csharp):
    1.  
    2. if (IsWalking())
    3. {
    4.     // The current ground info
    5.     var groundHit = characterMovement.groundHit;
    6.  
    7.     // Project forward vector along current surface normal
    8.     var forward = Vector3.ProjectOnPlane(GetForwardVector(), groundHit.normal).normalized;
    9.  
    10.     // Compute final forward position
    11.     var forwardPosition = GetPosition() + forward * GetSpeed();
    12. }
    The above code uses the speed so when the character stops it will be zero.

    By other hand, as part of the ECM2 continuous collision algorithm, it always projects the character's movement (its velocity) and reacts to 'future' collisions, you can get this information using the OnMovementHit event it will pass a MovementHit struct containing all the information about current hit.

    Kind regards,
    Krull
     
  16. NexonVision

    NexonVision

    Joined:
    Aug 30, 2018
    Posts:
    5
    Hey, I'm trying make my AI character jump over these steps. As you can see it only jumps over one step. Any suggestions?

    upload_2021-6-24_18-0-8.png
     
  17. NexonVision

    NexonVision

    Joined:
    Aug 30, 2018
    Posts:
    5
    Aight i fixed it This is what I did the ai now jumps up every step and correctly goes to his target upload_2021-6-24_21-2-3.png
     
    Krull likes this.
  18. Krull

    Krull

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

    An easier way to end a jump is use its StopJumping() method, for example in your OnLanded() method, as this are the "action commands" Jump() and StopJumping() to issue a character to jump.

    Code (csharp):
    1. protected override void OnLanded()
    2. {
    3.     base.OnLanded();
    4.  
    5.     StopJumping();
    6. }
    Regards,
    Krull
     
  19. NexonVision

    NexonVision

    Joined:
    Aug 30, 2018
    Posts:
    5
    man I am not smart thanks lol
     
  20. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Actually your auto-jump solution is quite clever! ;)

    Regards,
    Krull
     
  21. Predulus

    Predulus

    Joined:
    Feb 5, 2018
    Posts:
    19
    [Edit: SOLVED]

    I just entered a game jam (about 48 hours left), went to import ECM2 into a project, with Active Input Handling set to 'Both', and I have 29 errors like

    Assets\ECM2\Source\Characters\FirstPersonCharacter.cs(144,19): error CS0246: The type or namespace name 'InputAction' could not be found (are you missing a using directive or an assembly reference?)

    upload_2021-6-26_13-16-38.png

    Any idea why I'm still getting these after setting Both please Krull?
     

    Attached Files:

    Last edited: Jun 26, 2021
    Krull likes this.
  22. Predulus

    Predulus

    Joined:
    Feb 5, 2018
    Posts:
    19
    Thanks for clarifying that dude.
     
    Krull likes this.
  23. Predulus

    Predulus

    Joined:
    Feb 5, 2018
    Posts:
    19
    Ok, solved this .... New Input System needs to be imported from Package Registry still (so lame Unity!!)
     
    Krull likes this.
  24. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hi @Predulus

    Yes it's the missing New input system package from Unity, and sorry not being able to answer sooner, but happy to know you solved it!

    Regards,
    Krull
     
  25. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    48
    Hi @Krull, quick question, if I'm using Root motion for movement, should this be affected by the physics volumes that speed up and slow down? if not can they?
     
  26. ml785

    ml785

    Joined:
    Dec 20, 2018
    Posts:
    45
    Hi, how might you get Swimming example working with Third Person Character controller? When I place the Third Person Controller prefab into the scene and go into the water, the character's movement is unexpected. For instance, if you walk into the Swim material and hit Space, your character stays on the ground
     
  27. Krull

    Krull

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

    When using root motion you basically are controlling the animation, so instead of the joystick axis controlling how much force to apply it controls which animation to play and how fast to play it, so if you want your character to move faster / slower you'll need to alter your animation playback speed, e.g:

    Want to walk faster? Play the animation to walk faster. Want to turn 90 degrees? Play an animation that turns 90 degrees. etc.

    You can use the OnPhysicsVolumeChanged(PhysicsVolume newPhysicsVolume) event to check when a character changes its physics volume, from there you can use the CharacterMovement physicsVolume to get the current one and the passed newPhysicsVolume to get the new one, so you can adjust your animation playback speed accordly.

    Regards,
    Krull
     
    Broudy001 likes this.
  28. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hi @ml785

    Yes, this is correct since by default a character will not alter its control when on water volume as this implementation is game specific.

    I suggest you check the included DemoCharacter.cs (ECM2\Samples\Demo\Scripts) and the Swim example to see some options of how to handle this.

    Regards,
    Krull
     
    ml785 likes this.
  29. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    48
    Has anyone had an issue when they do a Build of their project, and the input for movement etc doesn't work? It works fine in Play mode, but not in a build?

    The included examples work in build, but not my scene, which is just a copy of the demo scene's objects and my modified player and cinemachine camera
     
    Last edited: Jun 30, 2021
  30. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Mmm, not quite sure here, but could be you character not getting its input action assets assigned so its not processing your input.

    Worth try using the old input system for testing just make sure you enable bot inputs as the active input handler, e.g: Project Settings -> Player -> Other Settings -> Active Input Handling -> Both

    Regards,
    Krull
     
  31. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    48
    Thanks,

    I'll have a look, its really odd, works in play mode, but not in a build, just bizarre
     
  32. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    48
    From what I can find, it seems to have been something wrong in the scene, though I can't pin down what.
     
  33. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    What unity version are you using and what is your build platform, so I will try to reproduce it as honestly have not seen or been reported it before.

    Thanks!
    - Krull
     
  34. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    48
    It would have been started in 2021.1.11f1, but I tried it in the current 2020 and 2019 LTS releases as well.
     
  35. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    and your output platform ?
     
  36. restush96

    restush96

    Joined:
    May 28, 2019
    Posts:
    37
    @Krull Hello, I have noticed after some >4 hours gameplay, it becomes lag and has errors pop up "Rotation quaternions must be unit length."
     

    Attached Files:

  37. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    48
    Windows, x86_x64
     
  38. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Thanks, I'll perform some tests this weekend to try to reproduce it and to isolate the cause.

    Regards,
    Krull
     
    Broudy001 likes this.
  39. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hi @restush96,

    I think this is caused by an overflow since rotation keep adding new value, so it reaches the float max value and cause a 'corrupt' value.

    The easiest way to solve is is wrap the yaw rotation, so it always stay within 0 to 360 degrees range, like:

    Code (csharp):
    1.  
    2. using ECM2.Components;
    3. using UnityEngine;
    4.  
    5. namespace ECM2.Demo
    6. {
    7.     public class RotatingPlatform : PlatformMovement
    8.     {
    9.         [SerializeField]
    10.         private float _rotationSpeed = 30.0f;
    11.  
    12.         private float _yaw;
    13.  
    14.         private void OnEnable()
    15.         {
    16.             _yaw = transform.rotation.eulerAngles.y;
    17.         }
    18.  
    19.         /// <summary>
    20.         /// Extends OnMove method to perform platform's rotation.
    21.         /// </summary>
    22.  
    23.         protected override void OnMove()
    24.         {
    25.             // Update platform's yaw rotation
    26.  
    27.             _yaw = Mathf.Repeat(_yaw + _rotationSpeed * Time.deltaTime, 360.0f);
    28.  
    29.             rotation = Quaternion.Euler(0f, _yaw, 0f);
    30.         }
    31.     }
    32. }
    33.  
    Kind regards,
    Krull
     
    restush96 likes this.
  40. Krull

    Krull

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

    Well I performed several builds and was not able to reproduce your issue, so this led me to think it could be related to some of your modifications, however the puzzling part is it works on the editor.

    Please make sure on your modified scripts you are still enabling the input actions and the SetupPlayerInput() method is called as this is responsible for initializing the character input system.

    I suggest you build a debug version with the Script Debugging option enabled, so you can debug the script as this will make it easier to detect the cause.

    Last but not least, If you set up a basic scene where I can be able to reproduce the issue, I'll take a look into it.

    Regards,
    Krull
     
  41. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    48
    Thanks for having a look. I'll see if I can get a scene working with like it again, and will let you know.
     
    Krull likes this.
  42. Rin-Dev

    Rin-Dev

    Joined:
    Jun 24, 2014
    Posts:
    420
    I've been wondering how to set my agentcharacter to walk instead of run? When I call MoveToLocation they always run there.
     
  43. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hi @Rin-Dev,

    From the top-down template, the agent works as intended, I mean it will move at it specified max walk speed when walking, or at it max run speed (maxWalkSpeed * sprintSpeedMultiplier) when running, however the included example animator does not handle the animation walking state, so it should be modified depending if character is walking or running.

    Regards,
    Oscar
     
  44. Rin-Dev

    Rin-Dev

    Joined:
    Jun 24, 2014
    Posts:
    420
    I forgot to come back and comment that I got it working by messing with the animation script instead of the main scripts.
    Thank you though!
     
    Krull likes this.
  45. yunum844

    yunum844

    Joined:
    Jul 6, 2021
    Posts:
    27
    Last edited: Jul 21, 2021
  46. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hi @yunum844,

    Unfortunately I am not familiar with that package, so probably its author could offer you a better perspective about using it with a different Character controller.

    ECM2 has been developed with extensibility in mind so you can build those features on top of it but honestly not sure about integrating other packages as it would mostly depend if the other package is deeply tied to its used character controller.

    Regards,
    Krull
     
    yunum844 likes this.
  47. Spazius

    Spazius

    Joined:
    May 22, 2018
    Posts:
    2
    This problem is really tedious, as I love using Enter Play Mode Options. For me it prints these errors always when pressing left mouse button or escape when using the first person character template, but not for any of the other templates. Same for any of the demos/examples using the fps character. I tried to look into it but with the new input system I don't even know where to start.
     
  48. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hello @Spazius

    Actually this is know limitation of the Unity new Input Sytems as you can see here

    So unfortunately you will need to enable Reload Domain in order to stop those error messages.

    Kind regards,
    Krull
     
  49. ILJI

    ILJI

    Joined:
    Nov 1, 2016
    Posts:
    6
    Hi @Krull !
    Thanks for developing ECM2!
    Not sure, if I am doing sth wrong, or if this have been discussed before:
    When jumping on a moving plattform, the character is always sliding when landing again. I already turned off the other options, but maybe there is sth else I can do? Thanks
    MovingPlattformSlideOnLanding.gif
     
  50. Krull

    Krull

    Joined:
    Oct 31, 2014
    Posts:
    349
    Hi @ILJI

    Thank you for purchasing ECM2 and happy to hear you like it!

    About your issue, I was able to reproduce it, it seems to be a bug with the character's not canceling the vertical velocity when landing on the platform (nice catch!) I will perform some tests and issue a fix for it.

    Regards,
    Krull
     
    ILJI likes this.
unityunity