Node not moved (new user question)

Hello,

I’m new with jmonkey, so sorry for the newbie question.

I try to achieve placing two node at different place in my scene, but I can only see one of my object in center of the screen.

This is my code:

[java]
public class TestApp extends SimpleApplication
{
@Override
public void simpleInitApp()
{
//Set camera
cam.setLocation(new Vector3f(0.0f, 50.0f, 0.0f));
cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

    //Create player ship
    Spatial s1 = assetManager.loadModel("Models/ship_textured.j3o");
    Spatial s2 = s1.clone();
   
    rootNode.setLocalTranslation(0.0f, 0.0f, 0.0f);
    Node n1 = new Node();
    n1.move(-10.0f, 0f, 0f);
    n1.attachChild(s1);
    rootNode.attachChild(n1);
    
    Node n2 = new Node();
    n2.move(10.0f, 0f, 0f);
    n2.attachChild(s2);
    rootNode.attachChild(n2);
    
    //Add a light
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);
}

@Override
public void simpleUpdate(float tpf)
{
    //TODO: add update code
}

@Override
public void simpleRender(RenderManager rm)
{
    //TODO: add render code
}

public static void main(String[] args)
{
    ShooterApp app = new ShooterApp();
    app.start();
}

}
[/java]

What is wrong in my code?

Thanks

First, you don’t have to use the setLocalTranslation() of the rootNode, so remove that. Next, instead of using move() on the spatials, use setLocalTranslation().

Thanks, for your answer, but the problem is still here.

The two nodes are displayed in the center of the screen.

Here’s the new code:

[java]
public class ShooterApp extends SimpleApplication
{
@Override
public void simpleInitApp()
{
//Set camera
cam.setLocation(new Vector3f(0.0f, 50.0f, 0.0f));
cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

    //Create player ship
    Spatial s1 = assetManager.loadModel("Models/ship_textured.j3o");
    Spatial s2 = s1.clone();
   
    Node n1 = new Node();
    n1.setLocalTranslation(-10.0f, 0f, 0f);
    n1.attachChild(s1);
    rootNode.attachChild(n1);
    
    Node n2 = new Node();
    n2.setLocalTranslation(10.0f, 0f, 0f);
    n2.attachChild(s2);
    rootNode.attachChild(n2);
    
    //Add a light
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);
}

@Override
public void simpleUpdate(float tpf)
{
    //TODO: add update code
}

@Override
public void simpleRender(RenderManager rm)
{
    //TODO: add render code
}

public static void main(String[] args)
{
    ShooterApp app = new ShooterApp();
    app.start();
}

}
[/java]

Try it with just cubes instead of your model. You move the camera pretty far away so maybe they are just so big that they overlap?

The code looks ok at quick glance so remove the only non-standard thing in it and see what happens.

It works with cube :frowning:
My model size is about 4 units, so distance are goods.

I’ve created the model with blender and converted it to j3o from the .blend file.

What can make the model always in the center?