Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Ragee · Mar 02, 2014 at 08:33 PM · charactercontrollerisgrounded

isGrounded not updating

I have a character that starts on a platform and the platform gets destroyed after a couple of seconds. My problem is that when the platform is destroyed the isGrounded is still true. Only after I move the character it gets false and the character finally starts falling. Anyone having the same problem and figured out how to fix this?

     using UnityEngine;
     using System.Collections;
     
     public class Player : MonoBehaviour 
     {
         public static Player instance;
         CharacterController cc;
         float dashSpeed = 10f;
         float gravity = 6f;
         Transform playerTrans;
         float moveTo;
         bool right, left = false;
         bool blockedLeft, blockedRight = false;
         bool allowInput = true;
     
         Ray rightRay, leftRay;
         RaycastHit hit;
         float rayLength = 1.2f;
         void Start () 
         {
             instance = this;
             playerTrans = transform;
             moveTo = playerTrans.position.x;
             cc = GetComponent<CharacterController> ();
     
         }
         
     
         void Update () 
         {
         
             if (Input.GetKeyDown(KeyCode.RightArrow) && allowInput && playerTrans.position.x < 4f && !blockedRight)
                 MoveRight ();
             
             if(Input.GetKeyDown(KeyCode.LeftArrow) && allowInput && playerTrans.position.x > 0.2f && !blockedLeft)
                 MoveLeft();
             
     
     
     //******Move Right****************//    
             if (right) 
             {
                 if (moveTo > playerTrans.position.x)
                 {
                     allowInput = false;
                     
                     cc.Move (Vector3.right * Time.fixedDeltaTime * dashSpeed);
                 }
                 else
                 {
                     allowInput = true;
                     cc.Move (Vector3.zero);
                 }
             }
     //*******Move Left***********//        
             if (left) 
             {
                 if (moveTo < playerTrans.position.x)
                 {
                     allowInput = false;
                     cc.Move (Vector3.right * Time.fixedDeltaTime * -dashSpeed);
                 }
                 else
                 {
                     allowInput = true;
                     cc.Move (Vector3.zero);
                 }
             }
     
     //**********Raycasting*******************//
             if(Physics.Raycast(transform.position,Vector3.left, out hit, rayLength))
             {
                 Debug.Log (hit.collider.tag);
                 if(hit.collider.tag == "Box")
                 {
                     blockedLeft = true;
     
                 }
                                         
                 
             }
             else
             {
                 blockedLeft = false;
     
             }
     
             if(Physics.Raycast(transform.position,Vector3.right, out hit, rayLength))
             {
                 Debug.Log (hit.collider.tag);
                 if(hit.collider.tag == "Box")
                 {
                     blockedRight = true;
     
                 }
                 
                 
             }
             else
                 blockedRight = false;
     
     
            //*****CHECK IF GROUNDED*********//
             if (!cc.isGrounded)
                 cc.Move(new Vector3(0,-1 * Time.deltaTime * gravity,0));
             Debug.Log (cc.isGrounded);
     
         }
     //*******Moving Functions***********//    
         void MoveRight()
         {
             right = true;
             left = false;
             moveTo = playerTrans.position.x + 1.0f;
         }
         
         void MoveLeft()
         {
             right = false;
             left = true;
             moveTo = playerTrans.position.x - 1.0f;
         }
     
     
     //Very ugly work around as the player jumps up slightly, but lower amount on multiplier or using Vector3.zero in some cases still skips updating isGrounded and shows true when it should not.
         public void UpdateCC()
         {
             cc.Move(Vector3.up * 0.2f);
         }
     }
 
Comment
Add comment · Show 7
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 robertbu · Mar 02, 2014 at 08:34 PM 0
Share

You need to be more specific about what scripts you are using. If the are non-standard, we would need to see the code that set 'isGrounded'.

avatar image fafase · Mar 02, 2014 at 08:34 PM 0
Share

What is your code?

avatar image Fattie · Mar 02, 2014 at 09:41 PM 0
Share

Actually EDIT your question, and just put it in there. You still didn't show your code for isGrounded. Just follow http://answers.unity3d.com/questions/196381/how-do-i-check-if-my-rigidbody-player-is-grounded.html

avatar image pafla · Mar 02, 2014 at 09:58 PM 1
Share

@Fattie: He is obviously using this: https://docs.unity3d.com/Documentation/ScriptReference/CharacterController-isGrounded.html

I'm not exactly an expert when it comes to using the Character Controller as I prefer using Rigidbodies, but I guess calling $$anonymous$$ove with a Vector3.zero whenever a plattform gets destroyed could be a quick (and dirty) workaround for your problem.

avatar image Ragee · Mar 02, 2014 at 10:24 PM 0
Share

Thank you so much pafla for that idea. It now at least works on the starting platform but now ins$$anonymous$$d it gets stuck on the next. How ever destroying another platform after the second one makes it fall again. Tried Vector3.up * 0.2 and it works all the time but now it looks ugly as the character jump every time a platform is destroyed.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

22 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 avatar image

Related Questions

bizarre collision modulations with character controller 1 Answer

controller.Move doesn't stay grounded when walking down slope 3 Answers

Problem with CharacterController.isgrounded 1 Answer

Animation through graphics in FPS controller, weird character controller issue, NEED help! 0 Answers

How do you make a characterController jump automatically when it reaches the edge of a platform? 0 Answers


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