Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by TarwaterPV · Oct 01, 2016 at 06:57 AM · bugjumpcolliders

How do I stop the engine from thinking it is still grounded when in the air?

Hello, I have a pretty complicated question even though it is actually a simple issue. I am trying to program a jump set up and I use ontrigger enter, stay, and exit to determine if the player can jump. I tried before with raycasts but it was giving us way too many weird behavior problems and each fix kept bloating the size of our code and giving more weird behavior problems so I eventually told the team to forget the raycasts and use pure physics, which work very nice.

Now the intended behavior is that when the player is grounded, the jump button adds force to the rigid body allowing it to jump, which that is what happens. Now there are two tags the player can jump off from, Floor and Enemies. Floor is static but Enemies are game objects that are navmesh agents and use a navmesh for their pathfinding to chase down the player. Enemies cannot jump so they stay on the ground or wherever the navmesh allows them to navigate to.

The bug occurs when jumping off of enemies. Occasionally, for some reason when the colliders exit, they don't show false for isGrounded, they stay true instead and it allows the player to continuously jump and it constantly adds force since if u hold the button, it adds that amount of force to the jump constantly. This does not occur with the Floor unless Floor is a vertical surface which we have taken great pains to ensure we have no vertical surface marked Floor. It only happens with the enemies even tho both use the same code since the tags are referenced in the same methods. I have added a height limit so you cant go too high, it actually forces the player back down by using a velocity change to negative and it turns isGrounded to false. However, its a cheap workaround and I would rather we eliminate this weird "flying bug" completely so that our jump mechanics can work as intended.

So tl;dr, the player flies continuously upward off enemies until hitting the height limit because for some reason isGrounded is still flagged true upon exiting the colliders even tho the code shows it is supposed to be false on exit. Does anyone have any ideas or suggestion as to why this is happening? Thanks.

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 TarwaterPV · Oct 03, 2016 at 07:34 PM

Thanks for the reply. I was able to fix it by adding a timer for how long the player can stay in the air. Once they exceed that time limit, they are forced back down by an add force call to the rigid body. I was only able to set this up because after very careful observation of what behaviors were going on, I discovered that isGrounded was working correctly. Therefore adding a timer did the trick. Thanks for the suggestions though.

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 AurimasBlazulionis · Oct 01, 2016 at 09:19 AM

Ok, what sets the isGrounded? Do you use OnCollisionEnter/Exit? Well, then there just count the collisions on specific tag. When you hit a floor, do something like floors++, the same with the enemies. And when you get OnCollisionExit, then just do floors-- and the same with enemies. And if both are 0, then you are not touching anything.

But could you tell what is wrong with raycasts? They work just fine. Here is a line of code I use if (Physics.Raycast (transform.position, Vector3.down, controller.height / 2 + controller.skinWidth + 0.02f, layerMask)). My movement system uses character controller. And I know that my character pivot point is in the middle of the object. So I take object height (in this case CharacterController height), divide it by 2, add skin width of the character controller and then add a small number just to check a little bit further than the controller ends. I use this calculation for max distance, and the layerMask is used to check the layers (not tags) to be used in the raycast. It is a one line if statement, works all the time and I do not understand what kind of problem you have.

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

75 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

Related Questions

Player keeps bumping when walking over to another sprite 1 Answer

Raycast can't detect items by player's feet 2 Answers

Player does not jump? 0 Answers

rigid.velocity.x = 0 for unknow reason 0 Answers

Question about MapCollider2D 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