Search Unity

CharacterController isGrounded problem

Discussion in 'Scripting' started by AtomMc, Oct 28, 2011.

  1. AtomMc

    AtomMc

    Joined:
    May 20, 2011
    Posts:
    26
    Hello, im experiencing a problem with the isGrounded function in Unitys CharacterController script.

    Each update I check to see if the capsule is grounded and using this function. I have exposed a variable in the inspector and set it equal to isGrounded. My character can only jump when grounded and has different run speeds for on the ground and whilst airbourne.

    However whilst my character is grounded (either stationary or running) the variable is seen to flicker on and off. This does not give any issues with jumping for some reason, although it affects the run speed of my character. The capsule has a height of 4 and radius of 0.75 and the ground is a standard cube.

    Has anybody experienced this problem also or has any insight into a fix. Thank you.
     
  2. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    Hi, yes, the same, i have posted before here some months ago, i didn´t understand how to solve it.. i hope someone can help here.. i will be checking this .
     
  3. AtomMc

    AtomMc

    Joined:
    May 20, 2011
    Posts:
    26
    Hey, yeah its an odd problem. I was searching around for fixes and found some which suggested multiple Moves may be the cause though I only carry out one Move per update.

    I would really appreciate any help with this. Thanks
     
  4. AtomMc

    AtomMc

    Joined:
    May 20, 2011
    Posts:
    26
  5. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Try to put your event to set the flag to is grounded at another location of the script.
     
  6. hatless

    hatless

    Joined:
    Dec 15, 2010
    Posts:
    48
    I've also been bitten by this in two unrelated projects -- I'd like to hear from anyone who understands the problem.
     
  7. AtomMc

    AtomMc

    Joined:
    May 20, 2011
    Posts:
    26
    I tried Tiles' suggestion, unfortunetly it didnt work.
    Due to the timescale of my project, ive had to search for an alternative method.
    Im now using a Physics.SphereCast to detect if the capsule is grounded which is so far working perfectly.
    Thanks for your posts and hope for a fix soon :D
     
  8. Wicked0Wizard

    Wicked0Wizard

    Joined:
    Jul 2, 2014
    Posts:
    1
    Well I had this problem too. I fixed it by applying setting my downward velocity to gravity every frame. Not adding it just setting it equal to. Thank you quill18creates on youtube for your cure.

    quill18creates
     
    Last edited: Jul 2, 2014
  9. HuskyPanda213

    HuskyPanda213

    Joined:
    Mar 24, 2013
    Posts:
    37
    I don't know exactly why that is happening (it happened to me too), but I suspect that if movement is called in a non-FixedUpdate frame it will cause the bug. So just move your movement code to FixedUpdate (not Update).