Search Unity

CharacterController, Animator & Root Motion Issue

Discussion in 'Scripting' started by RuinsOfFeyrin, Feb 12, 2015.

  1. RuinsOfFeyrin

    RuinsOfFeyrin

    Joined:
    Feb 22, 2014
    Posts:
    785
    Hey Everyone,

    So I have a model(humanoid) that is setup using Mecanim.
    The character is controlled using the CharacterController.

    The problem is that CharacterController.IsGrounded ALWAYS returns false at the beginning of a new frame (even if you are grounded) before any movement is attempted.

    If i check CharacterController.IsGrounded at the end of the frame (after performing a move) it will tell me I am grounded. However at the beginning of the next frame, IsGrounded is false again.

    I have tested this with a completely new project with only the model (with CharacterController attached) and a script that does the following in Update

    1) Check if we are grounded and if so Debug.Log letting us know we are grounded at the start of the function
    2) perform a CharacterController.Move where only gravity is applied to the Y axis
    3) Check if we are grounded again and if so Debug.Log letting us know we are grounded at the end of the function

    There is also a plane with a mesh collider on it for my ground (i have tried a cube with cube collider as well).

    Doing this it only reports we are grounded at the end of a frame, and never at the beginning. Which makes no sense to me as CharacterController.IsGrounded is supposed to report if we were grounded in the last frame according to the documentation.

    So this had me totally confused because previously (before using mecanim and just using the animation system) everything worked fine. So i tried fiddling with the Foot Ik options on my states. No change, still never grounded at the beginning of a frame.

    So then for the lack of anything else to try i unchecked "apply root motion" on the animator attached to the character and it is now properly reporting being grounded at the beginning of a frame. Obviously though root motion is no longer being applied....

    Does anyone have any idea why this happens? How to fix this? I have a couple work arounds I have thought of, but i would like to avoid this if possible.
     
  2. RuinsOfFeyrin

    RuinsOfFeyrin

    Joined:
    Feb 22, 2014
    Posts:
    785
    No one else has had this issue?
     
  3. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    Did you figure this out at all? I'm having issues with Apply Root Motion auto-applying gravity when a CC is enabled.
     
  4. Salim

    Salim

    Joined:
    Apr 25, 2011
    Posts:
    148
    Hello! I could fix a similar problem by controlling the Character Controller in LateUpdate():

    Code (CSharp):
    1. void LateUpdate()
    2. {
    3. myController.Move(myTransform.TransformDirection(new Vector3(0, myGravityValue, 0)) * Time.deltaTime);
    4. }
    Hope it helps!
     
  5. Netuddmeg

    Netuddmeg

    Joined:
    Mar 2, 2018
    Posts:
    14
    I have some problems with character controller and character animations.
    If I use .Move() and character anim code in Update() the animation sometimes jittered. If I move Move() and character animation to LateUpdate() the animation seams much better but the tps camera is also in LateUpdate() and it causes sometimes strange behaviour.
     
  6. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    660
    CharacterController.isGrounded is completely broken via a bug.

    Im surprised they have not released update / fix for this.

    You can see this easily by just Debug.Log the isGrounded state.

    Its terrible.

    I ended up having to write raycasting code to manage grounded state... then i just ditched characterControllers completely until they fix it.
     
  7. Milanis

    Milanis

    Joined:
    Apr 6, 2018
    Posts:
    55
    Wait.. so we can't use root motion at the moment without walking in the air? I'm just an regular 3D Artist trying to get along with all of this magical code things.. We're using root motion to control our locomotion system. Our current setup is using a motion controller, character controller and script for movement. Running around pretty well and i can even walk up a hill. But as soon as i want to walk downhill, the character just keeps walking in the air. My programmer tried certain "isGrounded" true and false variants to make the character fall but somehow it does not recognize if the character grounded or not. Is this an confirmed bug? @Unity-Devs!!
     
  8. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913