Search Unity

Character controller not staying on the ground

Discussion in 'Getting Started' started by Sulemanalimalik, Dec 12, 2018.

  1. Sulemanalimalik

    Sulemanalimalik

    Joined:
    Jul 26, 2017
    Posts:
    79
    My player is not staying on the ground on which i have applied character controller instead it's height keep getting increased as soon as it hits another object please help
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Can you share some code and screenshots of the appropriate components?
     
  3. Sulemanalimalik

    Sulemanalimalik

    Joined:
    Jul 26, 2017
    Posts:
    79
    okay this was the solution it might someone help someday.............. If you check Edit > Project Settings > Physics, check the 'y' value of the Gravity. -9.81 is a good setting (mimicing Earth's gravity). My player would go up hills but then not back down, and would start floating upwards if I jumped while on a slope, or if I went up a particularly steep area. I solved this by ticking the 'Is Walking' box on my First Person Controller, and setting the Gravity Multiplier to 'Apply Root Motion' box is also unchecked. 125578-princesshunt-floating-solution.png
     
  4. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Glad you figured it out. Thanks for sharing your answer to help the people of the future, as well.
     
    Sulemanalimalik likes this.
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It's not really an effective method though. You might want to consider transforming the movement vector by the ground angle, then movement down or up is a consistent rate and the character controller will stick to surfaces.

    You can transform a movement vector using something like:

    Code (CSharp):
    1.         Vector3 tangent = Vector3.Cross(normal, vector);
    2.         Vector3 newVector = -Vector3.Cross(normal, tangent);
    3.         vector = newVector.normalized * vector.magnitude;
     
  6. Sulemanalimalik

    Sulemanalimalik

    Joined:
    Jul 26, 2017
    Posts:
    79
    but the shortest :p but thanks for sharing more knowledge