Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

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

  1. arminiuspp

    arminiuspp

    Joined:
    Jun 15, 2020
    Posts:
    54
    Do you have any future plans to add a package feature for the new input system?
     
  2. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
  3. arminiuspp

    arminiuspp

    Joined:
    Jun 15, 2020
    Posts:
    54
    ooh ookay thanks!
     
  4. Sunwer91

    Sunwer91

    Joined:
    Jul 13, 2016
    Posts:
    5
    Hi @JanOtt
    Great job you have done with the plugin.
    I've been using it recently and I had a question about it, I read the documentation but I can't find something I'd like to add, but before doing code for it, I wanted to see if it exists but I didn't see it.
    Is there a direct way to change the camera distance from the character in 3rd person mode? For example like in Mario 64 that you could zoom the camera in or out from the character to see more of the environment?
    Thanks in advance.
     
  5. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Hi,

    To change the camera distance, you'd simply adjust the 'local Z position' of the 'Camera Target' gameobject (all the way in the controller's hierarchy: Root>CameraRoot>CameraControls>CameraTarget).

    And if you want to adjust the camera's distance while in-game, you could of course attach a simple C# script that changes the local Z position, based on user input (from the mouse wheel, for example).

    Hope this helps!
     
    Sunwer91 likes this.
  6. Sunwer91

    Sunwer91

    Joined:
    Jul 13, 2016
    Posts:
    5

    I will try it, thanks!
     
  7. JCardec

    JCardec

    Joined:
    Oct 26, 2015
    Posts:
    10
    Ok so, I see you made changes to your script causing it not to work. the problem is I'm using a custom controller script that used to work with the older version of your scripts but not with the latest version. when I use the jump function with my old script it no longer jumps. after going through the code I believe the problem lies within the OnGroundContactLost(), that seems to be it (tho self-thought coder over here, so not too sure). when I use the older version of the method it doesn't work. when I use the new version of the method, it's buggy in more ways than one. I don't want to redo my whole custom script to make it work, the easiest solution here is if you still have older version of your character package that I can re-import into my current project. the last time I posted on here was in april so it would be whatever version that you had back then. on the plus side lock-on and dashing still seems to work :)
     
  8. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Hi!
    I think the fastest solution here would be for you to export the CMF files as a .unity package (i.e. a custom package) from a project that includes your older, modified version of CMF, then import that custom package into your new project.

    If that's not an option, you could also contact me directly and I'll see if I can find an older version of the asset.
    That said, the current/"newest" version of the asset was released on Apr 7, 2021, which seems to line up with your description - are you referring to an even earlier version?

    Best wishes,
    Jan
     
  9. JCardec

    JCardec

    Joined:
    Oct 26, 2015
    Posts:
    10
    went ahead and sent an email to support@j-ott.com <support@j-ott.com>; hopefully that's the correct one. Thanks for the cooperation!
     
  10. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    257
    First of all: I love your character controller! I really do. Of all the controllers out there that I was able to get my hands on (e.g. Kinematic Character Controller, UFPS/Opsive, Realistic FPS Prefab, etc.), it's simply the best! It even works flawlessly with vehicle physics.

    However, your statement above regarding swimming makes me a bit sad. Disabling your controller and enabling another that handles swimming would make me lose all the advantages of your asset. You even use controller states internally already. Wouldn't it come naturally to just add another one for swimming?
     
    Last edited: Feb 6, 2023
  11. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Maybe I haven't expressed this quite right earlier, but the idea was to create a dedicated controller script (not a different controller) that handles the velocity calculations when the character is in water - this script then passes the calculated velocity to the 'Mover' component.

    It might sound more straightforward, but using different controller scripts is just a lot simpler to implement and maintain. It also keeps the different "states" (regular movement, swimming, flying, etc.) separate, allowing for a modular workflow later on.

    For example, if you were to implement the swimming mechanics directly into the 'AdvancedWalkerController' script, you'd not only have to create a new controller state, but also make sure that every function and calculation inside the script takes that new state into account - which would bloat up the script considerably and probably introduce a ton of bugs that you would then need to fix one-by-one.

    Switching to a different controller script on the other hand allows you to start from a clean slate, without having to consider any other controller code that might run before or after (and potentially breaking existing code).

    I hope this helps explain it a bit!
    Best wishes,
    Jan
     
  12. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    257
    Now I feel dumb. :) That actually sounds much more reasonable and it really didn't come to my mind. I will definitely try that. Thank you.
     
  13. ahmadriyandi

    ahmadriyandi

    Joined:
    Mar 22, 2020
    Posts:
    2
    hello, i want to ask about this package... how to specify ground layer? i can jump to my other character head and stand in there. how can i avoid this? and uh, it is possible to check ground without stick in it? just check
     
  14. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Hi,

    The CMF controllers use Unity's built-in collision layer system, so you can simply use the collision matrix in the physics settings to change which layers the controller should be able to collide with.

    I'm not sure what you mean by "checking ground without sticking in it" specifically, though. Could you elaborate a bit?
     
  15. Karmate

    Karmate

    Joined:
    Aug 30, 2014
    Posts:
    45
    is it possible to use this controller with z axis long capsule collider ?
     
  16. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Hi,

    My apologies for answering so late, I didn't get any notification for some reason (or I might have missed it).

    Regarding your question: It's not really possible to use a z-axis collider with the CMF system, unless you're planning on rewriting a lot of internal code.

    I'm assuming you're asking this because you want to use the CMF controllers for a quadruped-style character (like a dog/dragon/horse for example).
    If that's the case, I'd maybe suggest looking around for alternative controllers on the Asset Store that are designed for that exact purpose, as quadrupedal locomotion is really different from humanoid locomotion (which CMF was built around).

    I hope this helps!
    Best wishes,
    Jan
     
  17. AlanWilliams

    AlanWilliams

    Joined:
    Oct 18, 2018
    Posts:
    2
    Hi, I am trying to teleport the player to a new location. When I do this, it's as if the player is jumping back and forth and I have to press my interact button 'E' multiple times. After a while, sometimes it will eventually teleport but is there a way to stop this happening so it is an instant teleport to the new position?

    I have been through all scripts and have it when I press my button to teleport I interact, it moves the player to the new position. I am disabling all scripts (probably the long way using .enabled for all the scripts) in a Coroutine then calling my new position then after say 1 second, re-enabling the scripts but it still seems to do it.

    Any help would be greatly appreciated! Been sitting on this for a while now and rattling my brain at something that is probably very simple!

    Thanks!
     
  18. AlanWilliams

    AlanWilliams

    Joined:
    Oct 18, 2018
    Posts:
    2
    I managed to resolve this issue. All I had to do was access the Rigidbody and change isKinematic to true and back to false!
     
  19. GeekGuy42

    GeekGuy42

    Joined:
    Feb 12, 2021
    Posts:
    1
    Hello! I am using the FPS Movement prefab, how would I add a crouching system to this? I'm used to do so by changing the scale but I'm afraid it's more complex on this asset. A solution I came up with was changing the camera Y position and the collider height when the player presses the crouch key, I would also use the Ceilling Detector to detect any possible ceiling and avoid issues with player leaving the crouch position on a bad location, however I do not know if this is the better solution or if there is a simpler solution?
    Thx in advance
     
  20. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Hi,

    Changing the vertical camera height and collider height (as well as reducing movement speed) is pretty much how I'd try to do it.

    However, the 'Ceiling Detector' script isn't really meant to be used to prevent the character from 'un-crouching' in a bad location - for this specific case, I'd recommend writing some code that checks (via raycasts, for example) whether there's any colliders above the controller (and prevent un-crouching if necessary).

    I hope this helps!
    Best wishes,
    Jan
     
    GeekGuy42 likes this.
  21. Mr_TZ

    Mr_TZ

    Joined:
    Apr 5, 2018
    Posts:
    12
    Hi guys,i wanna to know how to avoid one character pushing another character moving???
     
  22. JanOtt

    JanOtt

    Joined:
    Apr 23, 2019
    Posts:
    183
    Hi,

    Since the CMF controllers are rigidbody-based, they will always push each other around (as a result of Unity's physics calculations).

    If your game's gameplay requires a different interaction between characters, you could (for example) put each character's rigidbody into different physics layers to disable collisions between them completely.

    Or, alternatively, add an additional collider (set to 'isKinematic') to one character as a child gameobject, which would prevent the other collider from pushing the first (but not vice-versa).
    Of course, you'd have to use physics layers here as well, to disable collisions between the (root) collider and the child (kinematic) collider.

    There's a few more options beyond these two, but it really depends on your specific game in the end!

    I hope this helps!
    Best wishes,
    Jan
     
    JamesArndt likes this.