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
1
Question by Avaista · Mar 19, 2012 at 05:44 AM · charactercontrollercollisionflags

Collision Flags on Character Controller flip between Below and None

I am playing with the Unity Standard Asset Third Person Controller, which utilizes the CharacterController.

I have s separate scripts that is supposed to work while the CharacterController is grounded.

On Update, the character Controller's collision flags seem to jump between CollisionFlags.Below and CollisionFlags.None.

When I walk uphill, the flags stay set to below, but going downhill standing still seems to flit between Below and None every update.

Is this a known behavior? I am almost certain the the third person Controller has not been changed...

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

2 Replies

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

Answer by davedx · Mar 19, 2012 at 07:09 AM

I don't have time to test right now, but I'd guess it's standard behaviour of the character controller - you're trying to move forwards using your inputs, which constantly puts the character slightly above the ground so he falls slightly down.

What we did in a game where you had to be able to slide down hills was write additional code to modify the character's y position according to the slope of the ground. This forced him to stay grounded.

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 Avaista · Mar 19, 2012 at 08:40 AM

So I think I discovered the reason that the collision flags were being flipped.

Unity Standard Asset ThirdPersonCharacterController applies gravity like so:

 function ApplyGravity ()
 {
     if (isControllable)    // don't move player at all if not controllable.
     {
         // Apply gravity
         var jumpButton = Input.GetButton("Jump");
         
         
         // When we reach the apex of the jump we send out a message
         if (jumping && !jumpingReachedApex && verticalSpeed <= 0.0)
         {
             jumpingReachedApex = true;
             SendMessage("DidJumpReachApex", SendMessageOptions.DontRequireReceiver);
         }
     
         if (IsGrounded ())
             verticalSpeed = 0;
         else
             verticalSpeed -= gravity * Time.deltaTime;
     }
 }

Basically gravity is only applied if you are not connected to the ground. Makes sense.

But the collision flags are based off of the movement. When the controller moved with 0 in the y, it did not hit the object beneath it, meaning that the controller was not grounded. On the next Apply gravity, because the object was not grounded from the last move, it applies the gravity, which meant now the controller was grounded, meaning the next time around verticalSpeed was set to 0, and would not hit collider again. This loops.

I can't imagine this is intended behaviors, though I noticed that when I commented out the if else and always applied gravity, the checks were consistent, but the character controller dropped like a brick once you stepped off of a platform, which makes sense(gravity was "accumulating" while on the platform).

I switched it to verticalSpeed = -.001; and it worked well enough, with the flags stating that their was a hit below each frame, while not having the character drop like a brick. Sadly, I found a better way of going about what I was doing(in terms of needed to know if the controller was grounded or not)

@davedx Thank you for your answer!

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to detect on which side my character controller was hit? 1 Answer

Problem detecting ground with collision flags and controller.move (vector3.down) 1 Answer

Excluding Gameobjects/Colliders from reacting with Collision Flags? 1 Answer

Collision with character controller and cube not working 1 Answer

Joystick movent and rotation on left joystick 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