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
5
Question by cheesehound · Feb 15, 2011 at 07:48 PM · charactercontrollerisgrounded

How does character controller's isGrounded() detect whether the character's on the ground?

I was initially hoping that character controller's isGrounded() operated purely on whether or not the bottom of the controller was colliding with anything, but I've got a rotatable character controller that, for example, can run on walls, and if I'm running up a horizontal surface I no longer get a true result for isGrounded().

Is there something else I can edit on character controller to change the behavior of isGrounded(), for example setting what relative vector to look for the ground on?

I can go and look at the colliders myself, I'm just seeing if there's a way to do this using isGrounded().

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

1 Reply

· Add your reply
  • Sort: 
avatar image
9
Best Answer

Answer by Bunny83 · Feb 15, 2011 at 08:11 PM

As far as i know isGrounded is just a wrapper for

if((controller.collisionFlags & CollisionFlags.Below) != 0)

You can check the collision bit flag if he collides above or at the sides.

CollisionFlags.Sides don't tell you what side you collided. You could use CharacterController.OnControllerColliderHit to get detailed information about all collisions of your charactercontroller.
The ControllerColliderHit structure gives you everything, the exact hit point, the object you collided with and the surface normal.

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 cheesehound · Feb 17, 2011 at 03:48 AM 0
Share

Thanks for the info, it helped me figure out what I was doing wrong. Foolishly enough, it was just that the CharacterController wasn't rotating with the rest of my object. I'm not too optimistic that I'll be able to change that situation, based on searching :(.

avatar image Bunny83 · Feb 18, 2011 at 02:35 AM 0
Share

Yeah, :D i tried it myself, but the CharacterController keeps aligned in space. A workaround would be to rotate the world around your player, but that involves a lot of calculations on your side. You could even do it without CharacterController and maybe use a normal capsule + rigidbody. Or maybe just a capsule-cast against the ground?

avatar image Salveiro · Jul 30, 2020 at 11:12 AM 0
Share

Helpful notice helped me a lot. This might help someone too: For my controller to work properly i wrapped CharacterController.isGrounded into: public bool IsGroundedBetter => (collisionFlags & CollisionFlags.Below) != 0 || ((collisionFlags & CollisionFlags.Sides) != 0 && currentNormals.Any(n => n.y > 0.1f));

But for that we need to store collisionFlags and collision normals. Those can be got from CharacterController.OnControllerColliderHit method as Bunny83 described.

avatar image PersonMon Salveiro · Jul 09, 2021 at 12:04 AM 0
Share

Salveiro, Can you elaborate on how you got this to work? I tried to use OnControllerColliderHit to store the normal of the hit, but it says .Any is not an extension of the normal.

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

2 People are following this question.

avatar image avatar image

Related Questions

CharacterController always starts not Grounded 2 Answers

How reliable are isGrounded checks? 1 Answer

Using isGrounded with a RigidBody 2 Answers

Why does my characterController code not apply gravity correctly? 0 Answers

How can I edit this script, that it will check if the character is standing on a specific layer? 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