Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Mecanim character automatic gravity - wtf?

Discussion in 'Editor & General Support' started by SunnySunshine, Apr 29, 2014.

  1. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    952
    Looking through the official mecanim example scenes from the asset store, I was surprised to discover that the mecanim controlled character in the "Animator Controller" example seems to get gravitation applied to it automatically. It has a script on it with a boolean variable "ApplyGravity", but that doesn't do anything. You can even remove the variable and gravity will still be applied.

    Intrigued, I dug further into this and found out gravity seems to be applied automatically if these terms are met:

    1. An animator component is added
    2. A controller is set for the animator
    3. Root motion in animator is turned on
    4. The avatar is set, and MUST BE HUMANOID
    5. A character controller component is added

    If any of these are changed for the game object "U_Character_REF" in "Animator Controller" scene example the gravity will stop working.

    I was a bit puzzled by number 4 in this list. No matter what I've tried, automatic gravity doesn't seem to work for a non-humanoid character. Indeed, in the example where they're using a generic model, they've also added a rigid body component.

    Is this automatic gravity behavior really intentional? I can't seem to find any official information about it in the documentation. And why does it only work for humanoid? That seems a bit inconsistent.
     
  2. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    952
    Aha, did a little further digging. The behavior for humanoid and generic is actually the same. To enable the gravity behavior, the animation needs to bake root transformation (Y) into pose.

    Now, I don't understand why the combo of:

    Bake into pose (Y) + Character controller

    should result in automatic gravity. That makes absolutely no sense to me. Especially since a character controller by itself does not fall.
     
    Last edited: Apr 29, 2014
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    It was my understanding that a character controller by itself WOULD fall o_O

    I dunno. Those things have always behaved weirdly for me. There's a reason I don't use them.
     
  4. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Can you link to the specific mecanim example you are using?
     
  5. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    952
    Sure. It's this one:
    https://www.assetstore.unity3d.com/#/content/5328

    The scene is called "Animator Controller".

    But you can reproduce this easily in any project.
     
  6. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    952
  7. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    You are using a character controller. A character controller is kind of a shortcut for using character movement if you don't want to deal with physics.
    If you remove that you can play your baked animation without your cube falling down.

    Edit: weird, I always thought that a character controller by itself would fall. I tried it, but it doesn't. I will look into that...

    Edit2: well, a character controller is affected by gravity if you use simplemove instead of move. So if the animator calls simplemove, because you baked the root motion into your animation, it will fall.
    You can:
    - stop using baked root motion and apply your own movement to the character controller
    - disregard the character controller as a whole
    - set your gravity to zero if you don' want any
    - stop using root motion in your controller and apply your own movement

    I would stop using the character controller, you will have more control over the outcome...
     
    Last edited: Apr 30, 2014
  8. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    952
    Ah, so that's why. Thanks for clearing that up.
     
    Last edited: Apr 30, 2014
  9. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,886
    Anyone got more info on this?

    Animator (Animator Controller + Apply Root Motion) and a CharacterController applies gravity somehow.