Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Disabling gravity for a Character Controller

Discussion in 'Physics' started by sergidoce, Nov 23, 2020.

  1. sergidoce

    sergidoce

    Joined:
    Jul 15, 2019
    Posts:
    1
    Is there any way to have like a Use Gravity option like in a Rigidbody but for a Character Controller? I find it very annoying that we can disable gravity for the entire game but not for a single Character Controller. I've tried to use a RigidBody for my game but I can't make it work.

    By the way I'm using Root Motion and not using any Move function or Simple Move.

    Thanks!
     
  2. kirbyderby2000

    kirbyderby2000

    Joined:
    Apr 28, 2017
    Posts:
    35
    The Character Controller doesn't interact with physics in the same way dynamic rigid bodies do; a Character Controller is essentially like a Kinematic Rigidbody (which doesn't interact / respond to gravity).

    You can't have both a RigidBody and Character Controller on a game object. With that said, you'll have to make the tough decision to pick one or the other for your controlling your character.

    If you want your Character Controller to have gravity, you'll have to write gravitational behavior on your own in your script that controls the Character Controller component.

    Brackeys did a surprisingly great video covering this topic and he goes over re-creating gravity using the Character Controller, you should give it a watch if you're interested. https://www.youtube.com/watch?v=_QajrabyTJc

    Edit: I do want to say you technically can use both a RigidBody and Character Controller, but you'll have to hack a state system that toggles between the two when you need it.
     
  3. BrownBot

    BrownBot

    Joined:
    Feb 27, 2013
    Posts:
    4
    I just discovered the same obscure issue, "normally" the character controller does not apply gravity.... all the information and tutorials will tell you to roll your own which I have.

    But if you apply root motion and bake the Y into the animation it does apply Physics.Gravity... seems very inconsistent to me.

    I can only guess that it is applying SimpleMove() instead of Move() internally if root motion is applied but Y is baked. only solutions I can find are:
    1. Set gravity to Zero in the project settings (not very flexible).
    2. Don't bake the Y into your animations with root motion.
     
    oiliossatos and baerbel like this.
  4. purificationalex90

    purificationalex90

    Joined:
    Dec 27, 2022
    Posts:
    2
    If you are using character controller & manipulating y level using root motion, without move/simple move method is not ideal i think.

    BTW, if you want to create a on/off trigger for gravity, create a function with boolean parameter _useGravity. If _useGravity == true then apply gravitational behavior and i really don't know how you will apply gravity without using move method. If _useGravity == false then simply return but it will not match with root motion behavior. I had to use it for only swim and ledge grab . For jump i don't like to use root motion. Because without any gravitational behavior landing or falling feels inconsistent to me.
     
    Last edited: Apr 30, 2023
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,321
    Rather than making 4 posts and deleting 3, please simply edit your posts.

    Thanks.