Generating a cube mesh with two given points

I’m attempting to create a script that takes two positions from the player, and creates a cube between those two points with a given height and depth. I can manage to generate a single face (Unity’s Mesh library makes it easy to do), but I run into trouble when I try to create the other faces. Since the mesh is generated between two points, it has the appearance of being “rotated,” but its forward vector remains relative to the world since the transform is never actually rotated. You can see an example of what I mean here:

alt text

This makes generating the other faces less than trivial (as far as I can tell) since I can’t just use the first face’s transform.forward to place the remaining vertices. If anyone has any experience with this let me know, and if you need any elaboration/code feel free to ask. Thanks!

The Cross Product of two vectors is a vector pointing at right angles to both those vectors. Think about how that gives you exactly the vector you need: one pointing in the depth direction of your cube, the displacement to the 4 vertices of the back face of the cube, given each of the 4 front vertices.

(BTW, well done getting that far first - you’ve actually done the hard part!)