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 /
This question was closed Aug 10, 2021 at 11:25 AM by lerola43l for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by lerola43l · Aug 10, 2021 at 02:03 AM · collision detectionfallingcapsulecast

CapsulCast is switching between false and true [SOLVED]

Hello, I am trying to get my CapsulCast to detect wether the Player is on the ground or not. It workes aslong the player is falling its giving a steady false for the grounded variable but when it starts hiting the ground it will start to switch between true and false... Is this a known bug?

 public void Gravitation()
         {
             //prüft ob der character aud dem boden steht
             CheckGround();
             if (IsGrounded == false)
             {
             Velocity.y -= Gravity * Time.deltaTime;
             }
             if (IsGrounded && Velocity.y < 0f)
             {
                 Velocity.y = 0f;
             }
             if (Velocity.y < MaxVelocity)
             {
                 Velocity.y = MaxVelocity;
             }
     
             PLAYER.transform.position = PLAYER.transform.position + new Vector3(0, Velocity.y * Time.deltaTime, 0f);
         }
         public void CheckGround()
         {
             Vector3 point1 = PLAYER.transform.position + new Vector3(0, Collider.height / 2 - Collider.radius, 0);
             Vector3 point2 = PLAYER.transform.position + new Vector3(0, -Collider.height / 2 + Collider.radius, 0);
     
             float castDistance = 0.1f;
     
             if (Physics.CapsuleCast(point1, point2, Collider.radius, Velocity.normalized, castDistance, Groundmask))
             {
                 IsGrounded = true;
             }else { IsGrounded = false;}
         }

I also tried using Physics.CapsulCastNonAll and i saw the same thing it switched between 0 and 1 when it should always detect the ground.

SOLVED: I found my mistake if ground is detectet my velocity will be 0 so in the next frame there will be no direction where the sphere will be cast so it will return false, then the velocity will go up again and it will cast and return true and then the loop begins again. To fix that I entered a fixed value for the direction because it always should check downwards.

 if (Physics.CapsuleCast(point1, point2, Collider.radius, new Vector3(0f, -1,f 0f), castDistance, Groundmask))



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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

126 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

Related Questions

How to get the center of a CapsuleCast or SphereCast on collision 1 Answer

Collisions: do they need two rigidbodies? 2 Answers

Player Colision help 0 Answers

How do I detect world particle collisions in Unity4.0? 0 Answers

physics ignore terrain collision on trigger 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