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 GVGiu · May 22, 2013 at 06:30 PM · collisionphysicscolliderplanegeometry

Using the UnityEngine.Plane struct, what's the best way to check if a collider is crossing said plane?

The function I was hopping for was something that like this:

 Plane plane;
 Collider col;
 
 if (plane.Intersects(col)) // or the other way around col.Intersects(plane)
 {
    // Do stuff
 }

Since I could not find such a function I created a test using the collider.bounds and testing for each point in the bounds, but I get a few false positives depending on the orientation of the collider and the plane. Any ideas on how to solve this?

Edit: One such false positives is when you have capsule collider rotated by 45 degrees and the plane is also oriented 45 degrees, the capsule could be completely on one side of the plane, but close enough to the plane that two of its bounding box vertices are on the other side of the plane, something like this:

 |      /
 |     /
 |   ...c
 |   . c.
 |  /.c .
 | / c...
 |/    
 +-------------
 
 / = plane
 c = capsule
 . = capsule bounding box limits


Ok, I did a workaround that solves my problem, though it's not the best solution, it's lightwheight enough and works for me. I check for the bounding box first and if the box collides, I check against the collider.

I found out that for spheres, capsules and boxes that's just some basic geometry, other types of colliders might be harder but I don't need to check against them so it's no problem for me.

Now I think the question is more of a feature request, as I think it should be a built-in function, a PlaneCast, working much like Raycasts do.

Comment
Add comment · Show 5
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 Tomer-Barkan · May 22, 2013 at 06:48 PM 0
Share

You could add a box collider of very thin dimensions to the Plane object. Then the physics engine will automatically identify any collisions for you and initiate the OnCollisionEnter() or OnTriggerEnter() methods, so you don't need to manually check for them.

Will that work?

avatar image GVGiu Tomer-Barkan · May 22, 2013 at 07:07 PM 0
Share

It could work, but I don't want to do that, performance is an issue and the plane is not fixed, it changes constantly so a box collider with triggerEnter would not be a lightweight solution I believe.

avatar image Tomer-Barkan Tomer-Barkan · May 22, 2013 at 07:17 PM 0
Share

I would think that the built-in unity functionality would perform better than hand tailored solutions, but I can't prove it... Anyway, if you want to write it yourself, at least share your code and give examples of false positives so we can try and help you fix it.

avatar image GVGiu Tomer-Barkan · May 22, 2013 at 07:39 PM 0
Share

But using a box collider is a hack, not a real built-in solution, it's like using a sphere collider and check all trigger enters ins$$anonymous$$d of a Physics.SphereCastAll. I'm pretty sure if your sphere would change size and position a lot, you'd be better off using periodic spherecasts (something like 1-5 per second) than using a sphere collider and changing it's size and position and all. Anyways, I'm thinking of a few solutions and about to implement them and test.

Show more comments

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

14 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

Related Questions

How can i create a character like dragon hill game, Digging underground, what collider should i use? 0 Answers

Camera gets flung off of the map when the player collides with certain objects. 0 Answers

Punching a crate 0 Answers

Tossing an object with the correct force at any distance from another so that it collides with the other 1 Answer

OnCollisionEnter() problems 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