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

feet sinking into ground when animation is played.

Discussion in 'Animation' started by karina_mady, May 4, 2014.

  1. karina_mady

    karina_mady

    Joined:
    Mar 16, 2014
    Posts:
    18
    My character's feet sink into ground when some animations are being played and I don't know how to fix it.
    I have the same settings for the capsule collider as in the mecanim tutorial, but for some reason the feet still go through the terrain.

    See below:
    $feet sinking.png

    Please help
     
    laralena likes this.
  2. BroVodo

    BroVodo

    Joined:
    Oct 2, 2012
    Posts:
    52
    yOffsetAnimation.png

    This might not be the answer to your problem but might help someone else. It is an option when an animation is imported. Bake the y position into the pose, then offset it by the opposite amount of how many units you need to move your avatar to touch the ground.

    Another culprit could be the skin thickness of the character controller. In that case have the feet of your avatar sticking out of the character controller capsule collider by the amount of the skin thickness.

    In my case it was a combination of both problems, in which case it's probably better to make sure the feet are sticking out of the character controller capsule collider first, then working out the amount to offset the animation in the import settings.

    Also, you might want to set the Foot IK check box in the inspector of your animation state. Do this before you set the baked y offset in the import settings.
     
    Last edited: Jun 17, 2015
  3. Paloo

    Paloo

    Joined:
    Sep 23, 2020
    Posts:
    10
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class EventManager : MonoBehaviour {
    7.  
    8.     private Dictionary <string, UnityEvent> eventDictionary;
    9.  
    10.     private static EventManager eventManager;
    11.  
    12.     public static EventManager instance
    13.     {
    14.         get
    15.         {
    16.             if (!eventManager)
    17.             {
    18.                 eventManager = FindObjectOfType (typeof (EventManager)) as EventManager;
    19.  
    20.                 if (!eventManager)
    21.                 {
    22.                     Debug.LogError ("There needs to be one active EventManger script on a GameObject in your scene.");
    23.                 }
    24.                 else
    25.                 {
    26.                     eventManager.Init ();
    27.                 }
    28.             }
    29.  
    30.             return eventManager;
    31.         }
    32.     }
    33.  
    34.     void Init ()
    35.     {
    36.         if (eventDictionary == null)
    37.         {
    38.             eventDictionary = new Dictionary<string, UnityEvent>();
    39.         }
    40.     }
    41.  
    42.     public static void StartListening (string eventName, UnityAction listener)
    43.     {
    44.         UnityEvent thisEvent = null;
    45.         if (instance.eventDictionary.TryGetValue (eventName, out thisEvent))
    46.         {
    47.             thisEvent.AddListener (listener);
    48.         }
    49.         else
    50.         {
    51.             thisEvent = new UnityEvent ();
    52.             thisEvent.AddListener (listener);
    53.             instance.eventDictionary.Add (eventName, thisEvent);
    54.         }
    55.     }
    56.  
    57.     public static void StopListening (string eventName, UnityAction listener)
    58.     {
    59.         if (eventManager == null) return;
    60.         UnityEvent thisEvent = null;
    61.         if (instance.eventDictionary.TryGetValue (eventName, out thisEvent))
    62.         {
    63.             thisEvent.RemoveListener (listener);
    64.         }
    65.     }
    66.  
    67.     public static void TriggerEvent (string eventName)
    68.     {
    69.         UnityEvent thisEvent = null;
    70.         if (instance.eventDictionary.TryGetValue (eventName, out thisEvent))
    71.         {
    72.             thisEvent.Invoke ();
    73.         }
    74.     }
    75. }
     
    SympaK likes this.
  4. davidson27

    davidson27

    Joined:
    Feb 10, 2018
    Posts:
    18

    This works in 2020!!
     
    BroVodo and SympaK like this.
  5. SympaK

    SympaK

    Joined:
    Apr 14, 2010
    Posts:
    134
    Thanks all of you people.
     
    BroVodo likes this.
  6. Bezoika

    Bezoika

    Joined:
    Sep 1, 2020
    Posts:
    1
    If anyone is having this issue and the offset didn't help, try unchecking "Use Gravity" on your characters Rigidbody.
     
    kadirbrky and BroVodo like this.
  7. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Hello, I have this same issue, except it doesn't appear to be offset when the animation is playing, but if the animation is interrupted the player moves down slightly. Applying your fix didn't really seem to help. I tried testing it out by increasing the offset to an insane amount and talking, it seems like changing the offset doesn't help, while it offsets during the animation, it reverts back to the normal offset...

    I'm using a rigidbody to move, I was using a character controller, but I removed it.

    I tried a million different fixes before finding this post, and disabling gravity won't help like the previous post said, cause as I mentioned, it was still occurring with a Character Controller and I replaced it with a rigidbody to fix it. I also tried setting transition settings to default and the issue still occurred. Sorry to necro, but do you know how to fix this?
     
  8. BroVodo

    BroVodo

    Joined:
    Oct 2, 2012
    Posts:
    52
    If you send me a project with the problem isolated I can take look
     
  9. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    I found out the issue WAS the animation, but no matter how much I played with the offset of the animation, it didn't fix it(I even tried setting it super high as a test, it made the character launch up until the animation was finished, then fall back down)

    I fixed it by setting the local position of the armature to 0 if it goes to far down, but it's more or less a bandaid fix... I'm not really sure how to send the issue isolated, the project doesn't really have too much in it, but it requires photon as the voice animation is being run through Photon Voice, also calling a lot of RPCs from Photon, so a lot of dependencies just to send you a tester... It'd probably be inconvenient for you if I sent the whole thing, especially as it's somehow 10gb haha.

    I wonder if me figuring out the cause of the issue helps? It's definitely caused by the animation, it seems the player moves down a slight amount every time the animation is interrupted...
     
  10. hanisherif1997_unity

    hanisherif1997_unity

    Joined:
    Jun 25, 2021
    Posts:
    14
    Thank you. Bake into pose for the root transform position (Y) on the required animation (the one responsible for the feet to sink in the ground) works like a charm!!!
    Thank you so much
     
    BroVodo likes this.
  11. kingdom216

    kingdom216

    Joined:
    Apr 13, 2021
    Posts:
    45
    I had this problem and it was due to root motion being ticked 'true' in the animator inspector
     
    MisterRogers, Mashimaro7 and spvn like this.
  12. ShubhamVIne

    ShubhamVIne

    Joined:
    Aug 16, 2020
    Posts:
    2
    This Helped in 2021 :)
     
    BroVodo and Mashimaro7 like this.
  13. metasota

    metasota

    Joined:
    Sep 8, 2021
    Posts:
    2
    This helped me in 2021, thanks
     
    BroVodo and Mashimaro7 like this.
  14. mickeeyj

    mickeeyj

    Joined:
    Feb 22, 2018
    Posts:
    3
    The tips that keeps on giving in Dec 2022. Cheers BroVodo
     
    BroVodo likes this.