Hey!
I’m working on a game where I need to make planes in the game itself… So, I’m wondering if someone know a way to make a plane, when you have the position of the 4 corners? Do I have to calculate the center, and then figure out the lenght/height… or is there a way to just “fill” in a plane inside those four corners?
What do you mean by ‘plane’? A plane has infinite extent (unbounded); or do you mean a quad or rectangular mesh? (Unity refers to rectangles in 3-d as ‘planes’, which probably contributes somewhat to the confusion.)
Also, what do you want to create exactly? Are you wanting to generate a mesh procedurally? Or just derive a transform from four points that form a quad?
If the latter, you can easily compute the transform using a little vector math. If you need further details on that, feel free to ask.
Well, I guess I want a rectangular mesh…
like, If I have 4 spheres, place them randomly out, and then want to use those 4 spheres as corners to a rectangular mesh…
I’ve used the LineRenderer line to make lines between the spheres, and want the space between those 4 lines to be filled… kinda…
If the corner positions are really random, they’re unlikely to be planar – your quad mesh would have a ‘crease’ along one diagonal. In that case, you’ll need to procedurally generate a mesh. It’s a trivial mesh, though, so easy to do – see the Mesh and MeshFilter api docs to get started. Alter natively, if you can constrain your corner points so they are planar, you could just instantiate a Plane-type GameObject and size/position it correctly.
The 4 corners position have the same height! (y position)
But, to intantiate a plane-type GameObject, I’ll have to calculate the center, the height and width right?
So I guess making a mesh with vectors will be easier!
You can make a mesh using the vertex coords (x, y, z).
Really?
Hmm… I’ll google that up =)
Actually, if the corners form a rectangle, computing the transform from the corners and instantiating a pre-made object (such as the built-in plane primitive) might be easier (as it just involves a little vector math and perhaps the use of Quaternion.LookRotation()).
Hmm…
I guess you’re right…