Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

[Released] Character Movement Fundamentals - A Rigidbody-based Character Controller

Discussion in 'Assets and Asset Store' started by JanOtt, Jul 1, 2019.

  1. Pixitales

    Pixitales

    Joined:
    Oct 24, 2018
    Posts:
    227
    Thanks, i am not good with writing camera scripts. I try cinemachine. I could add cinemachine component and set it to do nothing and let the camera controller do the work. I let you know if that works.
     
  2. Braanflakes

    Braanflakes

    Joined:
    Jan 30, 2015
    Posts:
    6
    Hey there! Just purchased the asset and I'm loving it so far. Is there any chance you'd add sprinting and crouching support? I've been tweaking the code over the last few hours to add in both, however it's very patchwork so it'd be cool to see those options natively.
     
  3. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    I might eventually add a few more specialized controller scripts to the package in the future, like some kind of "advanced movement controller" that includes built-in crouching and sprinting.

    Right now my main priority is streamlining all the existing scripts and get everything as stable as possible for version 2.0 - so any new features will have to wait until then.

    However, if you need any assistance or help with your custom implementation, you can always contact me at support@j-ott.com and I'll try my best to help!
     
    Braanflakes likes this.
  4. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    Hey @JanOtt any updates we can look forward to? I'm pretty excited about the stuff you've mentioned will change in V2. Do you have any other assets you are working on that we can start saving up for? :)
     
  5. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Hi toddkc,

    I'm currently finishing up the manual and doing some final checks, but apart from that, version 2.0 is pretty much ready to go. I'll try to upload the update in the next few days, if all goes well.

    After that, Unity will have to review the new update, which can take anywhere from a few days to a few weeks.
    Thanks for asking, but (at least for now) I don't have any new assets planned. If I do, I'll be sure to make some sort of announcement in this thread, though!
     
    Last edited: Feb 17, 2020
    toddkc likes this.
  6. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    609
    @JanOtt I'm excited to see what you have with 2.0! Thanks for your hard work.
     
  7. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Thanks @dock! The main goal for version 2.0 was to restructure and streamline all the existing code - along with a few new features that users have been frequently asking for (namespaces, separate input scripts).

    I'll post a more detailed breakdown here about all the changes and additions as soon as Unity finishes reviewing the asset.
     
    slimshader, Moona-Unity and toddkc like this.
  8. RainerBk

    RainerBk

    Joined:
    Aug 1, 2015
    Posts:
    1
    Hello, I wanted to ask a question how can I make the gravity of a planet? With this extension?
     
  9. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Hi!
    All controllers in the package can be rotated at runtime (by just directly modifying the transform's rotation or by using the 'rigidbody.MoveRotation' function), so for a "planet" setup, I'd recommend writing a simple script that continuously rotates the character so it's 'up' axis aligns with the vector between the character and the planet's center.

    If you're interested, please feel free to contact me via the support email (support@j-ott.com) and I'll help you set up an example scene and go more into detail!
     
  10. slimshader

    slimshader

    Joined:
    Jun 11, 2013
    Posts:
    190
    Yey, namespaces!
     
  11. Moona-Unity

    Moona-Unity

    Joined:
    Dec 12, 2019
    Posts:
    5
    Version 2.0 is up on the assetsore... will try it later.. Thank you @JanOtt
     
  12. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Quick update: Version 2.0 has just been accepted by Unity and can be downloaded at the Asset Store now.

    VERY IMPORTANT:
    This new version makes a few major changes to the package, so any scripts written for older versions (1.3 and below) will most likely not be 100% compatible! Please make sure to make safety backups of your projects before trying to import the new version!
    GENERAL:
    - Implemented namespace for entire code.
    - Renamed 'Resources' folder to 'Source'.
    - Fixed unnecessary memory allocation in some scripts.
    - Added (inspector) tooltips to some variables.
    - Some minor code improvements to improve readability.

    MOVER:
    - Overhauled and simplified mover inspector UI. Mover now supports proper editor undo/redo.
    - Streamlined mover layermask system. Mover now automatically uses the same layermask for raycasting as its gameobject's layer (as set in the physics settings).
    - Added (optional) ceiling detection script. This script can be attached to any object with an 'Advanced Walker Controller' script and will register collisions with the ceiling using the rigidbody's 'OnCollision' functions.
    - Added functions to change mover collider dimensions at runtime via script (see manual).

    CONTROLLERS:
    - Separated input handling from controller scripts. Input is now handled by a separate script attached to the same gameobject. This makes implementing custom input a lot easier.
    - Added two example input scripts for character movement (keyboard and gamepad controls).
    - Added two example input scripts for camera movement (mouse and gamepad controls).
    - Restructured controller script inheritance. All controller scripts now extend an abstract base controller script, 'Controller'. By extending from this script, users can easily use all the secondary scripts with their own custom controller scripts.
    - Controller scripts now have a 'Camera Transform' field. If assigning a camera transform, the controller will now move relative to that camera's view.
    - Merged 'Camera Walker Controller' and 'Basic Walker Controller' into a single controller script, 'Advanced Walker Controller'.
    - Added 'Simple Walker Controller', a very simple example controller script.

    PREFABS & SCENES:
    - Added two simple controller prefabs (located in Prefabs > Controller > Simplified).
    - Added a new example scene ('ExternalCameraScene') to demonstrate a possible controller setup where the camera is a separate gameobject as the character.

    MISC:
    - Added a generic 'Turn Toward Transform Direction' script as an alternative to the existing 'Turn Toward Camera Direction' script.
    - Added 'RotateObject' script, which is used in the new 'ExternalCameraScene'.

    That's it for now! If there's any questions about any of the new changes, please feel free to ask in this thread and I'll go into more detail!

    And as always, you can contact me via email (support@j-ott.com) anytime as well.
     
    Last edited: Feb 25, 2020
    twitchfactor and toddkc like this.
  13. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    609
    I just tried it the demo scenes, and it's a huge improvement, great work! Separating out the input and allowing external cameras will make a huge difference to my use of this asset. Thanks for your hard work and continued support!
     
  14. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Thanks! Glad to hear you like the new changes, @dock!
     
  15. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    @JanOtt I also LOVE the update. I made a VR controller with this that can switch between 1st and 3rd person, and I was worried about the amount of work it would take to update, but it was super easy. Thanks!
     
  16. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Thanks, good to hear that!
     
  17. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Hi everyone!

    I'm currently making a list of possible topics/questions about the package, that I can cover in short videos (5-10 minutes) each. The plan is to upload these videos on Youtube as I finish them.

    So if you have an idea for a topic, please let me know either by commenting in this thread or via email (support@j-ott.com)!

    I can't promise I'll get to all of them, but I'll definitely try to cover the most requested ones, if I find the time.
     
  18. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    I would love to know how you work through the logic/math for some of the features. That's what I struggle with, and why I bought this. Something you make look so simple like the gravity trigger spaces in the demo I would struggle with endlessly. Maybe that isn't a short video, but if you do one where you add a feature please talk through the logic in the code. I would love that more than 'change this setting on this prefab to do this' type stuff.
     
  19. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Yes, that might be tricky to fit into a video, unfortunately. Generally speaking though, most of my programming workflow heavily relies on sketching ideas out on paper and lots of unit testing.

    By the way: Are you referring to the 'FlipAtRightAngle' script, specifically? If you have any specific questions about that, please feel free to contact me via email and I'll try my best to answer them.
     
  20. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    I don't have specific questions about that script. Before I found your asset I was making a prototype for a game that did exactly that. I tried various methods of rotating the player vs rotating the world around the player, and spend months on it and never got it working properly. Then found your asset where you have that in a very easy, elegant solution. Being able to do that (for whatever purpose, like wallrunning, or swimming, or flying, or whatever) in a clean, modular way like you have done is something I would love to get better at. I do not ever sketch on paper, maybe I need to try that....
     
  21. unity_lJaPVdg5SsQ6FA

    unity_lJaPVdg5SsQ6FA

    Joined:
    Feb 13, 2020
    Posts:
    1
    So I'm trying to implement my own character controller (I unfortunatly don't spend any money on any tutorials or in game purchuses so that's why I haven't bought this package). I think It's going pretty well but my character can't move while standing on a moving platform (that also moves, the player can move when the platform stops at the ends). Totally understand if I have to buy this package to get help from here but I would really appriciate getting help with this. Is it that the rigidbody.movePosition doesn't work when the player is parented to a moving object or is it something else?
     
  22. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    You should probably start a thread in the 'Physics' subforum (https://forum.unity.com/forums/physics.78/) for that.
    This thread is only intended for any news, questions and announcements concerning the 'Character Movement Fundamentals' package.
     
    DeclanMerry, germanban and toddkc like this.
  23. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    I've just finished setting up a basic Discord server specifically for the package, for anyone interested:
    Please feel free to discuss the package in the #general with other users!
    And if you have any specific questions about the package or need technical support, you can of course always reach me at support@j-ott.com!

    Little disclaimer: I'm still quite new to Discord (and managing Discord servers), so if you have any suggestions for the server, please feel free to let me know!
     
  24. gamedeveloper145

    gamedeveloper145

    Joined:
    Mar 26, 2020
    Posts:
    1
    hello, great asset, I just want to know is it possible to use AI with your asset, if so how can I do it.
    Thank you in advance
    Edit: if you can, please show me how to make it work with A* pathfinding asset, that would be great.
     
    Last edited: Mar 26, 2020
  25. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    It's definitely possible to implement AI controllers using the package, but you'd probably have to write a custom controller script for that. You might want to check out chapter 8 (page 37) in the user manual, for a quick introduction on how to code custom controller movement.
    Of course, if you run into any problems, please feel free to contact me at support@j-ott.com anytime!

    Unfortunately, I don't have a lot of experience with pathfinding (yet), but if you have any specific technical questions, just feel free to contact me and I'll do my best to help!
     
  26. DiogoB_Pereira

    DiogoB_Pereira

    Joined:
    Jul 17, 2017
    Posts:
    1
    Hey, Great Asset, i love it.
    i just trying to make it crouch, and something is fixing the camera controls to y=2 and i cannot really see what it is, can u help me ?
     
  27. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    I'm fairly certain that this is caused by a smooth script (probably 'SmoothPosition'), depending on your controller's hierarchy.
    This should be easy to fix, but I might need to go into more detail to explain it - if you could maybe contact me directly at [support@j-ott.com], I'll get back to you as soon as possible!
     
  28. zachholt

    zachholt

    Joined:
    Aug 31, 2014
    Posts:
    10
    Hi! I was wondering what the best approach would be when making a local multiplayer game. I tried creating custom scripts and the new unity player input manager. Would I be able to just duplicate the inputs and add a number next to it so each player has their own input?
     
  29. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Hi zacholt! That's a difficult question for me to answer. Technically, this should be possible with the new input system by making use of the 'PlayerInputManager'/'PlayerInput' system.

    However, I've only just begun looking into the new input system myself and I'm still figuring out how to use it correctly and how to implement it into the 'CMF' package.

    Having said that, please feel free to contact me via the support email with a few more details about your specific game setup and I'll try my best to help!
     
  30. PeppersGamer

    PeppersGamer

    Joined:
    Jan 18, 2018
    Posts:
    17
    On play my character is in continuous falling and bypasses idle. I am using a humanoid character if that helps. Any suggestions?
     
  31. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Could you maybe contact me via email (support@j-ott.com) with a few more details? Also, if you find the time, a short video showing the issue would be very helpful to narrow down the problem.
     
  32. nastydiaper

    nastydiaper

    Joined:
    May 25, 2017
    Posts:
    491
    I am looking for the right place to add a footstep script. I am using the stepOffset field in BaseGroundDetection to determine my steps. I'm sure this is not what this field was meant for. Can anyone point me in the right direction for adding footsteps to the framework?

    Also, I am trying to setup Crouch so that it works on GetKeyDown() so it is a toggling crouch. But in HandleInput on BaseFirstPersonController, when I change
    Code (CSharp):
    1. Input.GetKey(KeyCode.C)
    to
    Code (CSharp):
    1. Input.GetKeyDown(KeyCode.C)
    I lose all crouch capability.
     
    Last edited: Apr 9, 2020
  33. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    That sounds like a question meant for the Easy Character Movement thread, just based on the function and variable names you've mentioned.
     
  34. nastydiaper

    nastydiaper

    Joined:
    May 25, 2017
    Posts:
    491
  35. Deleted User

    Deleted User

    Guest

    Hi ! Superb asset ! I'm trying to figure out what would be the proper way of moving the character into a specified location ? Is there an equivalent of Rigidbody.MovePosition ?

    Thanks !
     
  36. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    Hi! The best way to move a character depends on whether you want the change in position to look instant (like a teleport, for example) or smoothed out over several frames (like a very fast "slide" into the new position).

    For a 'smoothed-out' look, you can simply use either the Rigidbody.MovePosition() function, or even the regular transform.Translate function (or set the transform.position directly).

    If you need the the move to be instant, you'll have to use the transform.Translate function / set the transform.position directly as well as disable all SmoothPosition components on the controller right before the move (you can enable them again directly afterwards).

    That's because if you leave the SmoothPosition components enabled during the move, they'll try to smooth out the movement.

    I hope that helps!
     
    Deleted User likes this.
  37. Deleted User

    Deleted User

    Guest

    Oh ok so i can do this but i have to 'disable' Mover component or so ? Or at least input ?
     
  38. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    For most cases, there's no need to disable the 'Mover' and any 'Input' scripts, as far as I know. They should just keep working as usual, even with lots of translations being applied to the controller.
     
  39. majidarif

    majidarif

    Joined:
    Sep 11, 2015
    Posts:
    26
    Will this work with network games with server auth movement?
     
  40. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    I know several people who have used the package in networked game projects so far (both server-authoritative and peer-to-peer), but it's not a feature that works out-of-the-box - so you'll have to write some scripts to handle any network-specific tasks.
     
  41. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    For anyone interested: I've just released a short tutorial video on how to add a custom animated mesh to one of the included controller prefabs:



    I hope you'll find it useful! If you have any further questions about implementing animations (or the package in general), please feel free to contact me at support@j-ott.com anytime.
     
    Deleted User and toddkc like this.
  42. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    Of course it will, but there is no built-in network code. I made a `PhotonSetup` script that goes through and disables the things I don't want after a `PhotonView.IsMine` check. Throw a RigidbodyView on there and it works fine.
     
  43. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,363
    Hi I am curious what basic movement this asset adds over say the old Unity Character Controller starter kits (on the physics/movement level, not animation/cameras etc.)
    Also sticking to the ground is good but can it handle a fast moving/sliding character which flies off bumps when going fast?
     
  44. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    I'm not 100% sure which of the Unity character controller kits you're referring to (there's a good number of them, if I recall correctly), but generally speaking, all the included controllers in the 'CMF' package come with adjustable movement speed, various settings to fine-tune jumping (jump speed, jump duration), adjustable air control, custom gravity, adjustable step height and slope limit.

    I should mention that the main goal behind this package is to provide a stable and easily extendable base for your own custom controllers, so even though the included prefabs already cover a lot of common types of gameplay (first-person, third-person, top-down, [...]), the whole package is designed to be modified and adapted as needed.

    If the character's movement reaches a certain speed (and if the terrain is sufficiently "bumpy"), then the character will naturally lose ground contact at some point and, as a result, fly off.

    However, since this is a physics-based movement system, there's of course limits in terms of character speed - so it's probably not the best choice for a 'Sonic the Hedgehog'-type game (if that's what you meant).
     
  45. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,363
  46. Archit3ct

    Archit3ct

    Joined:
    Jul 26, 2019
    Posts:
    2
    Hey! I'm trying to debug the raycasts in the sensor class, I know the mover is instantiating it. I have tried to click the enable in debug mode, but they don't seem to appear in the scene shaded/wireframe. I'm using Unity 2019.3.9f1. I'm doing something wrong or is it a bug?
     
    Last edited: Apr 16, 2020
  47. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    I see! I'm familiar with the controllers in the 'Standard Asset' pack. From my experience, they are very rough around the edges unfortunately and require quite a bit of work to get them to move nicely and stutter-free.

    Then again, this pack seems to not have been updated for quite some time - I guess Unity has been focusing more on their 'complete project' packages and 'Microgames', which feature way more polished movement systems out of the box.
     
    andyz likes this.
  48. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    The debug visualization definitely works in 2019.3, at least on my computer (I just did a quick test to confirm this).

    Currently, the debug mode only draws the contact points and the contact normals that have been detected, not the rays itself, so maybe that's what might be causing some confusion.

    Anway, if you could contact me at the support email (support@j-ott.com) with a bit more information, I'll try my best to help you resolve the issue!
     
  49. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    185
    No, the package doesn't support root motion. I might look into that in the future eventually, but it's not a priority right now.
     
    Last edited: Apr 17, 2020
  50. HeyItsLollie

    HeyItsLollie

    Joined:
    May 16, 2015
    Posts:
    68
    I was wondering about root motion support just today, it'd be particularly useful to have when handling something like ladder movement (especially for mount and dismount).