I have a cube and I want to spawn another cube right on top of it. (it should work for other shapes like a pyramid, too). The tricky part is, that the first cube (or pyramid) moves randomly around.

So I guess what I need is the orientation of the first cube's top face I want to spawn my second cube at. But how can I get that information?

I can get the vertex normal with

# get the 1st mesh
mesh = obj.meshes[0]

# get the first vertex of the first material
vert  = mesh.getVertex( 0, 0)

# get the vertex normal vector
normal = vert.getNormal()

but I need the face normal for properly place my second cube on top of the first.

In the end what I want is to randomly stack objects on top of each other without gabs between them. And the newly spawned object always should should match the faces normal it is spawned on.

Thanks for any hint, cheers

  • $\begingroup$ You can get currently selected face normal with this. Also see this answer for more code on this. $\endgroup$ – Mr Zak Jun 27 '15 at 18:54
  • $\begingroup$ Thanks! However I need the script running in BGE... Sorry, someone has edited that out of the title. $\endgroup$ – Sputi Jun 28 '15 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.