Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
3
Question by boris709 · Mar 05, 2015 at 10:52 AM · character controllerisgrounded

CharacterController.isGrounded not working after Unity 5

Since I upgraded to Unity 5 this script no longer works. I have confirmed the program will run but the If (CharacterController.isGrounded) loop won't run. Does anybody know if this code no longer works? Thanks to anyone who could please tell me how to get this working.

I got the script from here

 #pragma strict
 // This script moves the character controller forward 
     // and sideways based on the arrow keys.
     // It also jumps when pressing space.
     // Make sure to attach a character controller to the same game object.
     // It is recommended that you make only one call to Move or SimpleMove per frame.    
 
     var speed : float = 6.0;
     var jumpSpeed : float = 8.0;//how high it jumps even though its called speed
     var gravity : float = 20.0;
     var rotateSpeed : float = 3.0;
 
     private var moveDirection : Vector3 = Vector3.zero;//static open to whole project, private
 
     function Update() {
         var controller : CharacterController = GetComponent.<CharacterController>();
         print("Line 17"); // DELETE
         if (controller.isGrounded) {
             print("Line 19"); // DELETE
             // We are grounded, so recalculate
             // move direction directly from axes
             moveDirection = Vector3(0, 0, Input.GetAxis("Vertical"));
             
             //rotate code
             transform.Rotate(0, Input.GetAxis("Horizontal")* rotateSpeed, 0);
             
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= speed;
             
             if (Input.GetButton ("Jump")) {
                 moveDirection.y = jumpSpeed;
             }
         }
 
         // Apply gravity
         moveDirection.y -= gravity * Time.deltaTime;
         
         // Move the controller
         controller.Move(moveDirection * Time.deltaTime);
     }
Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
12
Wiki

Answer by CicleOf14 · May 20, 2015 at 06:27 AM

I had the same problem and my fix was to basically call:

controller.Move(moveDirection * Time.deltaTime);

BEFORE calling:

if (controller.isGrounded)

...some logic might have to be reorganized a bit but it was a pretty simple fix (although it took me days to figure out!). What's strange is that the old (4.6) behavior of checking .isGrounded before calling controller.Move() still works with certain objects. Not sure why. I guess it doesn't matter, just make sure to always call the Move() method first from now on and you should be fine.

Comment
Add comment · Show 4 · 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 whisker-ship · May 03, 2016 at 10:31 PM 0
Share

pretty odd I had the same problem and your solution worked. seems like a bug if you ask me

avatar image Docboy · Feb 16, 2018 at 05:57 AM 0
Share

Try different solutions, but just this one function in Unity 2017.3,

I also think it is a bug You just have to ask "isGrounded" and the answer should be reliable

avatar image Pavus_The_Pug · Apr 21, 2019 at 05:31 AM 0
Share

Awesome! This worked and totally saved my game!

avatar image berzii · Apr 09, 2021 at 08:20 PM 0
Share

This one worked for me as well, however, I also had to set "Min Move Distance" property of the Character Controller to zero (or a very small number like 0.00001).

avatar image
1

Answer by MagyarPeter · Dec 16, 2020 at 10:52 AM

You have to push the charactercontroller to the ground with the gravity, and check the isgrounded after the "move" function.

 public float gravity = 10f;
 public float maxFallSpeed = 10f;
 CharacterController cc;
 bool ground = false;
 
     void Start()
     {
     cc = GetComponent<CharacterController>();​
     }
     
     void Update()
     {
     if(ground)
     {
     Y = Mathf.Clamp(Y, -0.1f, Mathf.Infinity);​
     }
     else
     {
     Y = Mathf.Clamp(Y - gravity * Time.deltaTime, -maxFallSpeed, Mathf.Infinity); //This is just a basic gravity, the point is to take the character down when it’s in the air, but don’t stop it from jumping.​
     
     cc.Move(new Vector3(0, Y, 0) * Time.deltaTime); // insert here the motion values
     ground = cc.isGrounded; //check the isgrounded after the "move" function, like this.​
     }​

Comment
Add comment · 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
0

Answer by Sam007xD · Apr 02, 2015 at 12:32 PM

I work in C# and i had this problem too. I did a port from unity 4 and it works perfectly, but there are some problems in unity 5 with "isGrounded". I put the player 1 unit above the ground and is not working (is grounded works perfectly with mesh collider). Here is when the player is colliding with the mesh collider (the mesh was made in blender) ![alt text][1]

but the player passes through the ground when it collides with it.

Also, there is a problem that when i select a brush on "paint height", i only can paint a circle![alt text][2]

we have to wait until the developers solve it. [1]: /storage/temp/43718-err1.png [2]: /storage/temp/43715-err2.png


err2.png (391.6 kB)
err1.png (171.3 kB)
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 CicleOf14 · Apr 19, 2015 at 09:12 AM 0
Share

Hi Sam007. Have you reported this "isGrounded" bug to Unity? I only ask because not only am I experiencing the "isGrounded" issue, but also a separate issue where my internet connection goes out while opening the Unity 5 editor. And since the only way to report bugs is through the editor, I would not be able to report this bug myself. Thanks.

avatar image
0

Answer by dragonboy77 · Oct 01, 2015 at 12:01 PM

I'm having the same problem in Unity 5 in that my character won't jump but the other input functions work properly with the following code (I got this from a tutorial):

 using UnityEngine;
 using System.Collections;
 
 public class PlayerMovement : MonoBehaviour 
 {
     CharacterController _controller;
 
     [SerializeField]
     float _moveSpeed = 5.0f;
 
     [SerializeField]
     float _jumpSpeed = 20.0f;
 
     [SerializeField]
     float _gravity = 1.0f;
 
     float _yVelocity = 0.0f;
 
     // Use this for initialization
     void Start () 
     {
         _controller = GetComponent<CharacterController> ();
     }
     
     // Update is called once per frame
     void Update () 
     {
 
         Vector3 direction = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
         Vector3 velocity = direction * _moveSpeed;
 
 
 
         if (_controller.isGrounded)
             //print ("We are grounded");
         {
             if(Input.GetButtonDown("Jump"))
             {
                 _yVelocity = _jumpSpeed;
 
             }
             else 
             {
                 _yVelocity -= _gravity;
             }
         }
 
         velocity.y = _yVelocity;
 
         _controller.Move (velocity * Time.deltaTime);
 
     }
 }
 

However, if I un-comment print ("We are grounded"); the script works like it should and the character (capsule in this case) jumps. I'm a beginner at coding so I don't really know what is happening and don't understand why the print function would have that effect because from what I have been reading it shouldn't. Is it a bug? lol.

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 KyleJensen72 · Mar 04, 2016 at 04:55 AM 0
Share

The print statement is between the if statement and the code block, meaning when you un-comment it, it will see it as a 1 line if statement and just print we are grounded and not execute any of the other code

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

11 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

Related Questions

CharacterController isGrounded confusion 1 Answer

Character Controller .isGrounded=false while moving left or right 1 Answer

isGrounded not working 2 Answers

How does the premade FPSController handle character physics? 1 Answer

Possible Character Controller issue? 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