Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
0
Question by Lesnikus5 · Oct 10, 2021 at 10:20 AM · physicsraycastcastcapsulecast

The CapsuleCast is broken.

         void CheckGround()
         {
             Vector3 p1 = transform.position + Vector3.up * capsule.radius;
             Vector3 p2 = transform.position + Vector3.up * (capsule.center.y - (capsule.height * 0.5f) + (capsule.radius * 3));
 
             float groundCheckDistance = p2.y - p1.y;
 
             p1.y += groundCheckDistance;
             p2.y += groundCheckDistance;
 
             if (Physics.CapsuleCast(p1, p2, capsule.radius, Vector3.down, out hitInfo, groundCheckDistance, Physics.AllLayers, QueryTriggerInteraction.Ignore))
             {
                 isGrounded = true;
             }
             else
             {
                 isGrounded = false;
             }
         }

Points p1 and p2 are initially correct, but the capsulecast appears below the desired position. Next, I have to add the height of the groundCheckDistance to the height of the points so that they rise to the correct height. But now they have the wrong values, nevertheless, giving the desired result. I don't understand how this works and why I need to do + = groundCheckDistance to each point in order for it to work.

The question is how to find the correct positions initially and get rid of a hack like this:

                  p1.y + = groundCheckDistance;
                  p2.y + = groundCheckDistance;


Second question: the documentation says: "The capsule is defined by the two spheres with radius around point1 and point2, which form the two ends of the capsule.". Following the instructions, this is how I find the first point:

 Vector3 p1 = transform.position + Vector3.up * capsule.radius;

Position + upward offset by capsule radius value.

According to the instructions that the capsulecast is defined by two centers of the spheres, finding the second point should look like this:

 Vector3 p2 = transform.position + Vector3.up * (capsule.center.y - (capsule.height * 0.5f) + capsule.radius);

But it doesn't work, although it should work. For some obscure reason, you need to add capsule.radius not once, but three times:

 Vector3 p2 = transform.position + Vector3.up * (capsule.center.y - (capsule.height * 0.5f) + (capsule.radius * 3));

I have to add not one capsule.radius, but (capsule.radius 3). Why is that? Finally, the center of the second sphere must be offset as the center of the capsule minus half the height of the capsule plus the radius of the capsule, but not three of the radius of the capsule. In general, the capsule cast is very confusing.


I want like in the picture: alt text

capsule.jpg (18.3 kB)
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

· Add your reply
  • Sort: 

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

243 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Physics.CapsuleCast Help 1 Answer

Why does CapsuleCast appear in the wrong place? 0 Answers

How to find the center of mass from capsulecast 0 Answers

Raycasting to the bottom side of a plane? 2 Answers

why are child colliders sometimes ignored? 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