Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

creating two parallel meshes

Discussion in 'Scripting' started by KushMathur, Oct 14, 2019.

  1. KushMathur

    KushMathur

    Joined:
    Jul 3, 2019
    Posts:
    22
    Hello guys!
    so I am working on a project in which their are supposed to be two parallel planes to be created from the position specified by the player. The player just gives an input of two vector3 coordinates and the code creates custom meshes using four sides of a square plane.

    I have and can calculate all the data of one plane, but the other plane I am supposed to create should be parallel to my previous plane and should be 0.3f outwards to it. How to proceed with it?

    Warm regards Untitled.jpg
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You can use the plane's normal vector. Then just use the position of the vertices and add 0.3f * normal to it.
     
  3. KushMathur

    KushMathur

    Joined:
    Jul 3, 2019
    Posts:
    22
    You are perfectly right, but due to some reason, the two planes are parallel but not equidistance from each other.
    Code (CSharp):
    1.   private void OutsidePlane(Vector2 FirstVertice, Vector2 SecondVertice, Vector3 MidPoint, GameObject game)
    2.         {
    3.             var name = "PlaneOutside" + i;
    4.             var vectoir1 = FirstVertice + FirstVertice.normalized * 0.3f;
    5.             var vectoir2 = SecondVertice + SecondVertice.normalized * 0.3f;
    6.  
    7.             Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
    8.             poly.outside = new List<Vector3>() {
    9.             new Vector3(vectoir1.x,0, vectoir1.y),
    10.             new Vector3(vectoir2.x, 0, vectoir2.y),
    11.             new Vector3(vectoir1.x, 2, vectoir1.y),
    12.             new Vector3(vectoir2.x,2, vectoir2.y),
    13.         };
    14.             // Set up game object with mesh;
    15.             Poly2Mesh.CreateGameObject(poly, PlaneDMaterial, game, "Plane");
    16.         }
    Untitled.jpg
     
  4. KushMathur

    KushMathur

    Joined:
    Jul 3, 2019
    Posts:
    22
    Oh I got the solution!

    It was my mistake, I normal I calculated was of the vector,which was being calculated from origin. So, I calculated the normal of the plane and then reprogramed it accordingly.

    Thanks a lot!