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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question isGrounded only working on slopes but NOT on flat ground?

Discussion in 'Physics' started by AddictedToKookie, Jun 13, 2020.


Is the design of the Unity Engine ugly and needs to be changed?

  1. Yes

    0 vote(s)
  2. Definitely Yes

  1. AddictedToKookie


    Jun 1, 2020
    So I am currently making a project in 3D with Unity for school and all I got were messed up bugs that destroy the enjoyability of this as a game engine. I have to use it so here I am

    This aside I was trying to get a basic character movement to work with in first person with walking and jumping and after hours of trying and dozens different tutorials I just took the example FPS project, took the code out I needed and shoved it in my project.

    In case you need the important part (the problem was the same with the basic characterController.isGrounded)
    Code (CSharp):
    1. void GroundCheck()
    2.     {
    3.         //reset values before the GroundCheck, stay if conditions aren't fulfilled
    4.         isGrounded = false;
    5.         p_GroundNormal = Vector3.up; //vertical
    7.         // only detect ground if there passed 0.2s since the last jump
    8.         if (Time.time >= p_LastTimeJumped + JumpGroundingPreventionTime)
    9.         {
    10.             // collect information about the ground normal, distance, direction when grounded
    11.             RaycastHit hit;
    12.             if (Physics.CapsuleCast(GetCapsuleBottom(), GetCapsuleTop(p_Controller.height), p_Controller.radius, Vector3.down, out hit, groundCheckDistance, groundCheckLayers, QueryTriggerInteraction.Ignore))
    13.             {
    14.                 // storing the normal direction of the found colliding object
    15.                 p_GroundNormal = hit.normal;
    17.                 // Check if the direction of the player and of the ground are in a similar direction and if the slope angle is small enough to stand on it
    18.                 if (Vector3.Dot(hit.normal, transform.up) > 0f && IsNormalUnderSlopeLimit(p_GroundNormal))
    19.                 {
    20.                     isGrounded = true;
    22.                     // snap to the ground, so the player doesnt float in a small distance over the ground
    23.                     if (hit.distance > p_Controller.skinWidth)
    24.                     {
    25.                         p_Controller.Move(Vector3.down * hit.distance);
    26.                     }
    27.                 }
    28.             }
    29.         }
    30.     }
    So as in the title, when having gravity pull the player down and he is clearly blocked by the floor, isGrounded stays false
    When I climb a slope tho isGrounded just turns true and I can finally jump (which is really weird off a 30 degree angle)

    I'm devastated on how bad Unity performs in general, how bad it is documented and if I don't get that to work soon I'll make an IceSkating game (cause inAir movement works at least) or just something with flying all around, cause the engine doesnt allow something else.

    P.S.: The design is just 2010 and I can't imagine why they haven't changed it yet this is sooo bad