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 dane-wheaton · Jun 04, 2020 at 07:08 AM · raycastspherecastspherecastall

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

Struggling with spherecasting, maybe you folks can help me out:

I am casting downwards, trying to find out whether the center of the cast is close to the edge of a horizontal surface. For example, if my glass of milk is spawned on the edge of the table, I want to know about so I can grab it before it falls.

The way I thought would make sense to do this is to get all the objects hit by a spherecast, then check the y position of each hit. If one of the hit points is lower than the center of the cast, the center must be close to an edge.

The problem with this approach is that Physics.SpherecastAll returns every single object in its path, not just the ones blocking it. This means that a cast performed above the center of a table will return the same objects as a cast which overlaps the edge of the table: they will each return both the table and the floor.

Doing a regular spherecast doesn't seem to be what I'm looking for either, since Physics.Spherecast seems to only retrieve information about the first thing it hits. I've never used SphereCastNonAlloc, maybe that's what I'm looking for?

Spherecasting may not be useful for this at all, I don't know - I'm considering just shooting a bunch of raycasts instead. I'm kind of having a stupid brain day tbh, so I feel like a simple solution is probably staring me in the face.

Edit: Layer masks wouldn't be flexible enough for me, because I want it to work for any random surfaces in any random level. Imagine jillions of glasses of milk being spawned all over castle battlements.

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

2 Replies

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

Answer by dane-wheaton · Jun 04, 2020 at 07:44 AM

In case a better solution doesn't come along, I'll post this since I already know it will work:

Shoot a ring of raycasts out around one central raycast. If any of the ring hits are lower than the central one, voila! You are close to an edge.

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

Answer by michaelfelleisen · Jun 04, 2020 at 07:27 AM

if you want to test against multiple objects but not every object you can use a layerMask for your Physics.SpherecastAll and but all objects you want to check against in a special layer https://docs.unity3d.com/ScriptReference/Physics.SphereCast.html

Comment
Add comment · Show 2 · 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 michaelfelleisen · Jun 04, 2020 at 07:32 AM 0
Share

if you want to detect if your glass is almost falling off the table multiple raycasts are probably the best idea. lets say you have 4 raycasts down from the edge of you glass you can test if all 4 raycasts hit the table. if one or more do not hit the table your glass is about to fall off

avatar image dane-wheaton · Jun 04, 2020 at 07:33 AM 0
Share

Ah, should have specified that layer masks wouldn't be flexible enough for me - I'll update the description

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

177 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

Related Questions

How do you perform a stationary SphereCastAll? 1 Answer

How to scan a surface of a GameObject and get the distance of every edge to camera 1 Answer

Should Items spherecast 0 Answers

Center of spherecast 0 Answers

How to Spherecast/Raycast diagonally? 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