reparentTo probelm

As most newbies I have come somewhat unstuck and hope someone can help.
I have a set of cubes floating in ‘space’ and want to attach one cube to another to make a shape, all in the 3d space.

Each cube is currently reparentTo(render). I need to make the cube ‘attach’ to the edge of the cube I selected as it gets moved close, I use the reParentTo to make one cube the parent of the other with an offset so it does not disappear, well that was the idea…

The second cube now follows the camera around and not the ‘other’ cube. Here is the code that does the reParentTo
The cubes are class instances

#This is inside a loop checking each cube for juxtaposition
self.attachCube = each # cube to attach cube to
#self.grabbedCube# the moving cube

What should I be attaching to to get the cubes to sit next together as ‘one’ panda programatically speaking.

Honestly, I don’t exactly understand what you like to do. But here is an example how you can build a scene graph with cubes. I assume that the side length of one cube is 2.0 units and the center is at 0.0, 0.0, 0.0 (If you export the default cube from blender that is what you get).

cube0 = loader.loadModel("cube.egg")
cube1 = loader.loadModel("cube.egg")
cube2 = loader.loadModel("cube.egg")


Given this assumptions the three cubes are aligned to each other.

I think he wants the cubes to snap some how.

You can just take the cube and reparent to cube to some other cube with a given offset. This way when you move the original base cube all the cubes move with it.

Thanks for the replys. I will get on and try it.

The ‘snapping’ together can be done programatically as the cubes approach each other in the scene.

The bit I am stuck on is getting the cubes to act as one model so moving one moved all ‘attached’ in the scene.

Its just that the way I was doing it was having strange effects on the scene, as I said the cube followed the camera, after attaching, rather than staying with the other cube and doing some strange clipping and distance issues.

Thanks again and I wil try a simple case first rather than the complex one

I just thought,
Does it make any difference if the cubes are first reparentTo(render). Do you have to ‘undo’ this before reparentTo the other cube?

No, you just need to use wrtReparentTo() instead of reparentTo().

A quick check says that the wtrReparentTo is the answer I am looking for

Thanks !