# Generating a cube mesh with two given points

 0 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: 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! more ▼ asked Aug 14 '11 at 02:37 PM ElijahT 1 ● 1 ● 1 ● 1 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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!) more ▼ answered Aug 14 '11 at 02:43 PM Waz 6.5k ● 23 ● 33 ● 71 Brilliant! I'm less than familiar with vector math and imagined there would be a simple way to do it. Thanks so much! Aug 14 '11 at 02:50 PM ElijahT add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x2247
x1403
x300
x146
x38

asked: Aug 14 '11 at 02:37 PM

Seen: 1446 times

Last Updated: Aug 14 '11 at 03:27 PM