Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Create an Edge Collision where a Plane and a Mesh intersect

Discussion in 'Scripting' started by SpaceJoker, Dec 1, 2023.

  1. SpaceJoker

    SpaceJoker

    Joined:
    Apr 27, 2018
    Posts:
    15
    Pretty straight-forward. I have two Gameobjects, one is a Mesh and one is its children. The children is empty, located within the X, Y coordinates of the mesh but at an arbitrary Z axis. In the script where I create the object I also create a Plane pointing up, originating at the height the object is on.

    Code (CSharp):
    1.     planarObject = new GameObject("PlaneObject");
    2.         planarObject.transform.parent = meshObject.transform;
    3.         planarObject.transform.position = new Vector3 (_meshObject.transform.position.x, meshObject.transform.position.y, transform.position.z);
    4.  
    5.         Plane plane = new Plane(Vector3.up, Vector3.Distance(planarObject.transform.position, Vector3.zero));
    I want to create an EdgeCollision2D that runs along the points where the Plane intersects with the original mesh, which has its own Mesh Collider.

    How could I do it?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,320
    SpaceJoker likes this.
  3. SpaceJoker

    SpaceJoker

    Joined:
    Apr 27, 2018
    Posts:
    15
    I appreciate the response, but I'm not trying to generate a mesh, this seems to be more complicated than the problem I have. I want the points on the surface of a mesh (already rendered with its own collider) that intersects with a plane, and then using those points to generate a 2D collider.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,320
    I wasn't suggesting generating a mesh.

    I was pointing out that the same techniques to boolean-intersect a large quad (analogous to your plane) with a mesh (which would compute you the contact line that you seek) likely apply to this problem.

    Otherwise, try hacking it out with a series of equally-spaced raycasts, casting parallel to the plane in the direction of the mesh surface you wish to obtain, sort of like an elevation slice.
     
    SpaceJoker likes this.