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
2
Question by spilth · Oct 25, 2010 at 10:55 PM · collidersphereintersect

How to detect what percentage of an object is inside a trigger?

If the player is controlling a sphere and I want the game to end when the sphere enters a goal volume (a cube collder), how can I detect if the sphere is entirely/95% inside the trigger, not just touching it?

Comment
Add comment · Show 3
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 Jesus_Freak · Oct 25, 2010 at 11:28 PM 0
Share

that's impossible! at least in javascript, i dont know ANYTHING about c+, but im sure there's some complicated script just for that.

avatar image Peter G · Oct 25, 2010 at 11:50 PM 1
Share

It is actually possible. And, language independent. You could do it in JS or C#. Unity does not have any built-in routine for checking that but I would search for it in your browser, or pick up a book on geometry. The formula is probably rather complicated, but you could implement it in Unity just like any other algorithm. And since you are using spheres and cubes, the volume is easy to find.

avatar image IJM · Oct 26, 2010 at 12:29 AM 0
Share

It is actually very simple, at least when it comes to the OBB and sphere. You just need a bit of linear algebra... =)

4 Replies

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

Answer by Eric5h5 · Oct 26, 2010 at 02:46 AM

How about getting the distance between the sphere's position and the cube collider's position...if it's a smaller distance, then a larger percentage of the sphere is inside the cube, more or less. That would only work perfectly for two spheres, but it would generally work for a sphere and a cube.

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 spilth · Oct 27, 2010 at 03:24 AM 0
Share

A tutorial elsewhere got me thinking of this solution and it ended up working well.

avatar image
1

Answer by Tobbe Olsson · Oct 26, 2010 at 01:07 AM

I would set up multiple gameobjects with triggers that are based on the percentage you want. That's how I've done proximity mines and other proximity based solutions. Sounds like a lot easier of a solution too!

If you are making a soccer type goal, I would just place the collider inside the goal so when it touches the collider and triggers it, it would only count as a goal because you placed it at 95% of the diameter of the ball inside the goal.

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 Peter G · Oct 26, 2010 at 01:16 AM 0
Share

I like it. Especially if the OP doesn't need perfect accuracy. Vote up :).

avatar image
0

Answer by IJM · Oct 26, 2010 at 04:13 AM

You can combine transformation matrix of your Box GameObject and it's BoxCollider.size to get OBB. Once you have a OBB, you can combine rotation matrix of your Box with Sphere's radius and Sphere's position to get 6 points. The only thing left to do is check if these points are located within the OBB. If all 6 points are inside, sphere is 100% inside. Quite simple.

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 Herman-Tulleken · Oct 26, 2010 at 05:01 AM

A sphere is approximately 95% inside a trigger if it is touching a smaller trigger.

So simply make your trigger smaller.

In this case, make the dimensions of the trigger smaller by [some value] of the diameter of the sphere. You can calculate [some value], or, just use an easy value (like 95% of the diameter) This is, like I said, just an approximation, but you wouldn't be able to tell it visually from the real thing.

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

No one has followed this question yet.

Related Questions

Make a capsule collider BETWEEN 2 objects 0 Answers

Need to Find the Radius of an Object? 2 Answers

Rigidbodies not reacting to one another 2 Answers

When two triggers intersect, when are enter and exit events called? 1 Answer

collider bounds intersect but than for a UI button element 0 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