Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 artygrand · Mar 01, 2021 at 03:02 PM · colliderfind

Is it possible to find objects that intersects arbitary 3d plane?

I have 4 Vector3 points and many many objects with colliders in scene. This points every frames can be different.

How can I find objects within this convex quadrangle?

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
0

Answer by CodesCove · Mar 01, 2021 at 07:14 PM

You could make your own meshcollider to find the objects in the plane like this (just example):

Add new GameObject then this component to it (notice that component requires MeshCollider in the same GameObject).

 [RequireComponent(typeof(MeshCollider))]
 public class CustomPlaneCollider : MonoBehaviour
 {    
     MeshCollider meshCollider;
     Mesh mesh;
 
     public void Start()
     {
         this.mesh = new Mesh();
         this.meshCollider = this.gameObject.GetComponent<MeshCollider>();
         this.meshCollider.sharedMesh = mesh;
         //just an initial plane.. set any values you like
         this.SetCollisionPlane(new Vector3(0, 0, 0), new Vector3(0, 0, 3.1f), new Vector3(4.3f, 0, 0), new Vector3(8.3f, 0, 5.3f));
         //triangles definition. This always stays same..
         this.mesh.triangles = new int[] { 0, 1, 2, 2, 1, 3 };
         this.ResetCollider();
     }
 
     //Set any coordinates for the vertices as you like. Call in Update or from ext components. Remember the plane is made of two triangles
     public void SetCollisionPlane(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4)
     {
         this.mesh.vertices = new Vector3[] { p1, p2, p3, p4 };
         this.ResetCollider();    
     }
 
     private void ResetCollider()
     {
         this.meshCollider.isTrigger = false;
         this.meshCollider.convex = false;
     }
 
     //Testing...
     public void OnTriggerEnter(Collider other)
     {
         Debug.Log("Trigger enter: " + other.name);
     }
 }

You can call the SetCollisionPlane method in Update or from external code to set new position to plane.

Notice1. The plane is made of two triangles so it can bend depending how you set the coordinates.

Notice2. This example requires that your objects have collider set in Trigger mode & has Rigidbody.

Notice3. The GameObject you are using as host to this meshcollider sets the reference transform to the mesh also. By moving the GameObject the mesh and collider are moving also. Same goes for rotation and scaling. If you are moving the meshcollider that way then attach also Rigidbody to it (kinematic).

Hope this helps.

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 artygrand · Mar 02, 2021 at 06:21 AM 0
Share

Oh, thank you for try. But I should make it also for static colliders.

If nothing helps me, I will try bunch of raycasts along plane.

avatar image CodesCove artygrand · Mar 02, 2021 at 08:36 AM 0
Share

ok, you can also try to add rigidbody to the plane itself and leave the objects static. Should still be ok

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

150 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

Related Questions

Spawning blood splatter at the point the bullet hit a collider? 1 Answer

Getting Objects from CheckSphere 0 Answers

Find all objects inside box collider 4 Answers

How can i find all *_LOD1 objects in a scene? 1 Answer

Locate a game object using rays 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