Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by gnp89 · Aug 28, 2013 at 12:59 AM · movementcharactercontrollergravityisgrounded

CharacterController isGrounded toggles value

My character controller isGrounded toggles its value even if the movement vector magnitude is zero. And when I walk it keeps toggling its value. So, if I want to jump, sometimes it doesn't respond because it says it's not grounded. But when you're playing it looks completely grounded. What do you think is happening?

 public float walkSpeed;
     public float rotationSpeed;
         
     public float gravityAcceleration;
     public float verticalSpeed;
         
     public float jumpVerticalSpeed;
         
     private CharacterController controller;
         
     public bool grounded;
         
         
     void Start () {
         controller = GetComponent(typeof(CharacterController)) as CharacterController;
     }
         
         
     void Update () {
             
         Vector3 movement = Vector3.zero;
             movement += transform.forward * Input.GetAxis("Vertical") * walkSpeed * Time.deltaTime;
             
             
         grounded = controller.isGrounded;
             
         if(!controller.isGrounded){
             verticalSpeed += gravityAcceleration * Time.deltaTime;
             movement += transform.up * verticalSpeed * Time.deltaTime;
         }else{
                 if(Input.GetKeyDown(KeyCode.LeftControl)){
                 Debug.Log("jump");
                 verticalSpeed = jumpVerticalSpeed;    
             }else
                 verticalSpeed = 0;
                 
          }
             
             
             transform.Rotate(0,Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime,0);
             controller.Move(movement);
             
     }

I have a public bool variable in order to see controller.isGrounded value in the inspector.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image amirblum · Oct 07, 2014 at 09:21 AM 0
Share

I have the same exact problem. Did you ever solve this?

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by LukeWaffel · Sep 28, 2015 at 10:17 PM

Actually @gnp89 and @armirblum , there is a very good reason for this,

When the charactercontroller touches a service, it shows it's grounded. When your script notices this, it sets the vertical velocity to 0, which means, there is no change in velocity. But this also means, the player get's pushed up a really tiny bit because of the ground and the collision and stuff. So when it moves up this tiny tiny bit, it get's off the ground, which makes the controller think it's not grounded anymore. When your script picks up this change, it will force it down because you implemented fake gravity. And then it happens again and again.

To fix this issue, you simply set the downwards velocity to -0.1f, or another small value, instead of 0. This means, the player will be forced down always, just by a really tiny amount. this way, the charactercontroller will always think it's grounded, and you will always jump when needed.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image legoblaster1234 · May 23, 2019 at 07:18 AM 0
Share

Thank you for your answer. I just wanted to share how little I needed to do to fix this since it feels so little yet made such a large difference. This is what my code was before:

 CharControl.$$anonymous$$ove(new Vector3(0, VerticalVelocity * Time.deltaTime, 0));
 VerticalVelocity -= Gravity;

And this is what my code was after:

 VerticalVelocity -= Gravity;
 CharControl.$$anonymous$$ove(new Vector3(0, VerticalVelocity * Time.deltaTime, 0));

so to fix my problem (in visual studio) all I had to do was press ALT + up arrow to fix my problem.

avatar image
0

Answer by lucidcloud · Oct 23, 2020 at 04:23 AM

@gnp89 I rarely use the isGrounded method of the character controller, since even with all the changes you can make collisions still make it buggy. Instead it the Update function, I get the position of a gameObject using gameObject.transform.position, and only jump if that position is less than any float between 0.2 to 0.5. This depends on what value you are receiving when you use transform.position. If the gameObject has already jumped, then the position will be greater than the the float, so you can use it as a condition along with Jump.triggered to make a character jump. If you want to prevent jumping when a character falls off a platform, simply do -0.5 < pos.y < 0.5.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AleMarcati · Jan 17 at 06:26 PM 0
Share

I don't think that's a very good solution. That only works if in your game the character never goes up or down unless it's jumping. So no stairs, no elevators, no slopes.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Adding gravity to character and grounded checks are not working? 0 Answers

When my player climb something, after a certain point it start to float 0 Answers

Problem with CharacterController.isgrounded 1 Answer

Sphere + rigidbody + character controller 1 Answer

How reliable are isGrounded checks? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges