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 /
avatar image
0
Question by SeaLeviathan · Jun 28, 2017 at 06:00 PM · collisioncapsulecast

Collision detection with Physics.Capsulecast is very spotty

Im working on a better type of collision detection for my capsule player, because a regular line raycast is very unreliable on slopes and stairs. I decided to implement a capsulecast for collisions and it worked, but only sometimes. My isGrounded bool changes from true to false pretty randomly depending on where I look with my FPS player.

     private void grounded()
     {
         if (isGrounded)
             hitdistance = 1f;
         else
             hitdistance = 1f;
         
         if (Physics.CapsuleCast(transform.position + (transform.up * 0.5f), transform.position + (transform.up * -.5f), 0.5f, -transform.up, hitdistance, layer))
             isGrounded = true;
         else
             isGrounded = false;
     }

the changing hitdistance is from a tutorial on Youtube, not sure if it is neccassary.

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 Trevdevs · Jun 28, 2017 at 07:21 PM 0
Share

I'm confused as to what the script is for is the for collisions between player and stairs, player and ground

if its the player and the ground just attach a character controller component to it and use the charactercontroller.isgrounded property.

Your making it a lot harder on yourself by doing it all from hand hope this gives you an idea :)

avatar image SeaLeviathan Trevdevs · Jul 07, 2017 at 09:02 PM 0
Share

Sorry I never got a notification on this comment lol. The script is for being able to jump on stairs and slopes, because raycast goes in the middle of the player, and does not detect the sides of the player. Character Controller had a really basic problem where the gravity would be applied to the character nonstop, making its degree of usefulness drop to 0 for any project besides a top down shooter. I already fixed my problem though, I just made a trigger on the feet of a player character, and whenever anything comes into its collision it just sets an isgrounded bool to true, then i can jump, and when there is no collisions it is not grounded, very simple. Thanks for response, but I already knew about charactercontroller.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bingo675 · Nov 04, 2018 at 07:48 PM

I know this post is old, but I had the same problem and solved it by simply extending the raycast which checks for isGrounded a tiny bit further than the raycast which bumps the player up.

So, first check for isGrounded (in order to set your gravity, ability to jump, etc.):

 if (Physics.Raycast(headPoint, Vector3.down, out groundHit, myHeight + 0.0001f, ignorePlayer))
         {
             isGrounded = true;
         }
         else
         {
             isGrounded = false;
         }

Then, later, bump the player up if he's poking through the ground:

 if (Physics.Raycast(headPoint, Vector3.down, out groundHit, myHeight, ignorePlayer))
         {
             transform.position = new Vector3(transform.position.x, (groundHit.point.y + myHeight / 2), transform.position.z);
         }



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

102 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

Related Questions

Why is CapsuleCast/Raycast performance effected by rigidbody? 1 Answer

CapsuleCast not registering.... 3 Answers

Test stationary capsule against colliders in scene. 2 Answers

Collisions: do they need two rigidbodies? 2 Answers

How to keep CapsuleCast() from sweeping? 2 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