How to create a mesh using coordinates?

I have a game in which I want to create a plane using the coordinates that I get from user clicking the mouse.
I know that to create a mesh you need vertices and triangles but I can’t seem to use the transforms that I get from the mouse clicks. How can I go about this?

mouse coordinates are in 2D, what are the actual coordinates you’d like to use in 3D?

also there are a lot of tutorials and done code on how to create a plane mesh, whether just a quad or a subdivided plane. do you have some specific issue with how to approach this?

I am going to try to explain what I am trying to do in the best way possible. I have the main camera pointing towards the X-Z plane. I press the left mouse button and get the coordinates of that point. I want to get the points and create a mesh using them.

ok, that’s great, but how do you know that the mouse coordinates are actually on that XZ plane? (they’re probably not)

An even better way, since there is absolutely nothing new under the sun, is to find the most popular game out there using this particular mechanic, then type its name into Google, like so:

“unity make nameofthegameyouarecloning”

in the general case, you want to get a ray from the mouse pointer directed away from the player.
then you want to intersect this ray with an imaginary plane coinciding with the XZ plane. now you have found the point in 3D.

here’s a method that will help you find the point of intersection

static public bool RayPlaneIntersection(Plane plane, Ray ray, out Vector3 intersection, float epsilon = 1E-7f) {
  var intersected = false;

  var point = -plane.distance * plane.normal;
  var denom = Vector3.Dot(ray.direction, plane.normal);
  var delta = point - origin;
  var num = Vector3.Dot(delta, plane.normal);

  intersection = new Vector3(float.NaN, float.NaN, float.NaN);

  if(denom.IsZero(epsilon)) { // line is parallel to the plane
    if(num.IsZero(epsilon))  // line is contained by the plane
      intersected = true;

  } else {
    var t = num / denom;

    if(t >= 0f) {
      intersected = true;
      intersection = ray.GetPoint(t);
    }
  }

  return intersected;
}

the XZ plane you want can be defined as new Plane(Vector3.up, Vector3.zero)
it’s best to leave the epsilon the way it is

you get the mouse ray with ScreenPointToRay

I don’t know of any game like this.

Thank you. This gets me the point but how do I use them to create a mesh.

You create the list of verts, you connect them into triangles, just like any mesh.

Here’s an ultra-simple example of a triangle being created out of three vertices:

https://github.com/kurtdekker/makegeo/blob/master/makegeo/Assets/makesimpletriangle/makesimpletriangle.cs

That project has tons of other simple examples, making cubes, spheres, capsules, etc.