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 /
This question was closed Mar 04, 2021 at 05:05 PM by pucylek for the following reason:

Other

avatar image
0
Question by pucylek · Mar 02, 2021 at 10:08 PM · movementcharactercontrollerisgrounded

Problem with CharacterController.isgrounded

CharacterController.isgrounded seems to only sometimes return true when I'm moving and always returns false when standing still. Any idea what I'm doing wrong?

 [SerializeField] private CharacterController controller;

 [SerializeField] private float speed = 12.0f;
 [SerializeField] private float gravity = -9.81f;
 [SerializeField] private float jumpHeight = 3.0f;

 private Vector3 velocity;
 
 void Update() {
     
     if (controller.isGrounded && velocity.y < 0) {
         velocity.y = 0.0f;
     } 

     float x = Input.GetAxis("Horizontal");
     float z = Input.GetAxis("Vertical");

     Vector3 move = transform.right * x + transform.forward * z;

     controller.Move(Time.deltaTime * speed * move);

     if (controller.isGrounded && Input.GetButtonDown("Jump")) {
         velocity.y = Mathf.Sqrt(jumpHeight * -2.0f * gravity);
     }
     
     velocity.y += gravity * Time.deltaTime;

     controller.Move(velocity * Time.deltaTime);
 }
Comment
Add comment · Show 2
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 benjaminfranklineatsfruit · Mar 03, 2021 at 03:01 PM 0
Share

@pucylek Could you perhaps add the code block that you use to detect ground?

avatar image pucylek benjaminfranklineatsfruit · Mar 04, 2021 at 12:20 PM 0
Share

I'm using the built-in isGrounded property of the CharacterController game object, what I posted is the whole script.

1 Reply

  • Sort: 
avatar image
0

Answer by Efe_Yilmaz · Mar 03, 2021 at 03:34 PM

The velocity unit is self-defined in its editor. Maybe that's why it didn't work. Maybe change the name or use physics 2D ' s overlapcircle. https://docs.unity3d.com/ScriptReference/Physics2D.OverlapCircle.html you can learn it how to solve the problem with overlapcircle.

Comment
Add comment · Show 2 · 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 pucylek · Mar 04, 2021 at 12:24 PM 0
Share

Thank you for your response, I tried using Physics.OverlapSphere (since I'm working with 3d and not 2d) and it seems that the problem isn't with detecting ground since I still can't jump when standing still. Do you have any idea of what the problem could be?

avatar image Efe_Yilmaz · Mar 05, 2021 at 10:08 AM 0
Share

Did you tried on enter , on stay and on exit methods ?

Follow this Question

Answers Answers and Comments

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

Related Questions

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

CharacterController isGrounded toggles value 2 Answers

Top-Down Movement in Unity 1 Answer

8-Axis 3D Top Down Movement 1 Answer

How to Logically Match Ground Slope While Using This Code? 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