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
0
Question by AlwaysSunny · Jun 09, 2012 at 12:21 AM · collisionraycastspherecast

SphereCast and CheckSphere failing to catch collisions.

Basically I need to know what inner workings can make these checks false, even though everything I can see indicates they should be true. Details below:

Trying to make a gameobject warp to a point, but it must check for a valid destination first.

Step 1:
If a SphereCast hits something, use the hit point for step 2 (warps to closest edge of thick objects)
If not, use the spherecast termination point for step 2 (limits distance that can be covered by a warp)

Step 2:
Do a CheckSphere at the coordinates from step 1 for added insurance.
If it hits nothing, this should be a valid location to warp to.

And that's all wonderful when it works, but it frequently fails in this scenario:
Both checks always fail together (seemingly). I'll often wind up stuck inside thick objects if the desired warp point was close to the thick object's center. The failures seem to only occur when the warping object is in direct contact with the obstacle object. I can see that causing the SphereCast to fail, but it seems like a CheckSphere should realize it's completely inside of a BoxCollider, right?

None of the objects can move during the check. The checks are performed in one frame in FixedUpdate, and I've toyed with improving the physics solver quality and fixed timestep.

Any advice as to why this can fail?

Comment
Add comment · Show 1
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 Matt-Downey · Jun 17, 2012 at 05:19 AM 0
Share

Ins$$anonymous$$d of using the word fail/succeeds, could you say, true/false. I think I know what you are saying, but my common sense is a lot worse than my program$$anonymous$$g.

I interpreted the first fail as the sphereCast returned false, and the second fail as the checkSphere returned true (therefore the position the player wanted to move to was occupied).

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Matt-Downey · Jun 17, 2012 at 05:04 AM

First something that might give you a little insight.

Physics.SphereCast will return false if the imaginary sphere starts its "sweep" while already inside of an object.

Basically, you can think of Physics.SphereCast as:

 if(!Physics.CheckSphere(transform.position,...)) //if the current position is not occupied
     {
     Physics.SphereCast(); //then cast the sphere as you would suspect
     }

Looking at why they would both fail, knowing this, I would guess that what is happening, is that from Physics.SphereCast() the default RaycastHit information is being returned: normal = Vector3(0,0,0), distance = 0, etc. This would mean the next check is checking at the origin of your map Vector3(0,0,0) in world space and looking for a collision within whatever radius. Try removing any colliders from the position Vector3(0,0,0) in world space and see if the second statement returns true every single time. If so then that was why the second statement was failing. The fix for the first statement is relatively hard, I would suggest using a smaller radius for the spherecast (by at least 0.11).

Furthermore: in edit (tab)-->project settings-->physics you can change the variable "min penetration for penalty" to a lower number like 0.01 or 0.005 (or lower although it is the law of diminishing returns) until the collisions are precise enough for your tastes, which should make everything work better. (If you do this, instead of subtracting 0.11 from the radius you can subtract 2*n + 0.01 instead.)

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

Physics.SphereCast please help understand 0 Answers

Using Trigonometry for Collision Detection 0 Answers

Lay a Sphere on a Point 3 Answers

How do you perform a stationary SphereCastAll? 1 Answer

How to detect which side is the raycast hitting? 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