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 otherrobin · Jul 05, 2014 at 09:32 PM · collisionphysicsraycastspherecastspherecastall

How do you perform a stationary SphereCastAll?

I am attempting to find all colliders within a sphere volume. To do this I am using Physics.SphereCastAll. However, I do not need to send the sphere along a path and I am running into a few problems because of this.

Problems:

  • When distance is set to 0, no colliders are found.

  • When distance is set to a small value (.1), RaycastHits are only found at the borders of the sphere. The interior of the sphere does not trigger hits at the starting position.

The hit testing works as expected if I move the sphere beyond its starting position. For example, if I move the sphere back by a diameter, and set distance = diameter, I get the results I expect.

However, this is not ideal for two reasons:

  1. It seems hacky - I feel like the Physics.SphereCastAll is not behaving as expected

  2. If I have objects at the position where I am now starting the SphereCast, some of them will trigger hits. This is not desired because they are outside the real volume I am testing.

How can I accomplish this stationary SphereCast without changing the position? Should I be using some other method?

I can share more code or pictures if needed. The objects I am detecting hits on is a 3d grid of 1x1x1 cubes.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by rutter · Jul 05, 2014 at 09:37 PM

You want Physics.OverlapSphere. It sounds like it does pretty much exactly what you're looking for.

There are a few caveats:

  • Instead of getting collision information for each hit, you just get an array of nearby colliders.

  • The sphere checks against the outer AABB of each collider, not necessarily the collider itself.

In most cases, those aren't important concerns, but they're good to know about.

Comment
Add comment · Show 1 · 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 otherrobin · Jul 05, 2014 at 09:41 PM 1
Share

Thank you! This looks like exactly what I need, and it is most likely more efficient as well. Thanks for the heads up on the caveats as well, although for my needs I don't think they will be a problem.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Collision position - Improving on the 'grounded' mechanic 2 Answers

Trying to find whether a point is close to the edge of a surface 2 Answers

Make Ray hit own collider 1 Answer

RAYCAST KNOWLEDGE HELP!!! 1 Answer

SphereCast and CheckSphere failing to catch collisions. 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