Spatial.rotate and Spatial.addChild

Hi, this code doesn’t do what is supposed to do:
``

    parent.attachChild(spatial);
    spatial.scale(0.01f);
    spatial.setLocalTranslation(-2, 0, 4);
    parent.rotate(0, (float)(Math.PI/2.5), 0);
    spatial2.scale(0.01f);
    spatial2.setLocalTranslation(-2, 0, 4);
    parent.attachChild(spatial2);

I want to attach a spatial, then rotate the parent node, and only then add another spatial.
But instead the rotation is executed AFTER that the second spatial is attached… is this stuff supposed to be executed on the update loop?

I think you misunderstand how a scene graph works.

If you put someone in the driver’s seat of a car… then rotate the car… then put another person in the driver’s seat of the car then they will be sitting on the first person’s lap.

If you want to put someone in a different seat… then put them in a different seat. In this case, that’s means multiplying their relative position by some rotation…probably the inverse of what you were doing to rotate the parent.

This could be helpful: http://wiki.jmonkeyengine.org/doku.php/jme3:scenegraph_for_dummies

Aww… my bad!

I’d like to (re)read it, but is very slow to load! Did it migrate correctly to the new wiki?

Intermediary node FTW! :smile:

    parent.attachChild(spatial);
    spatial.scale(0.01f);
    spatial.setLocalTranslation(-2, 0, 4);
                    
    Node parent2=new Node();
    parent2.attachChild(spatial2);
    spatial2.scale(0.01f);
    spatial2.setLocalTranslation(-2, 0, 4);
    parent2.rotate(0, (float)(Math.PI/2.5), 0);
    parent.attachChild(parent2);