Position of a child

Hello i have a problem regarding the position ( Transformation ) of child in a node i want to place a new object in the exact same spot as the child. But i just get the position of the parent node.

any help is very appreciated

Node ship;

public void simpleInitApp()
ship = new Node("ship");
ship.attachChild(makeCube("id1", 0f, 0f, 0f));
ship.attachChild(makeCube("id2", 1f, 0f, 0f));
ship.attachChild(makeCube("id3", 2f, 0f, 0f));

if (name.equals("Shoot") && !keyPressed)
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
CollisionResults results = new CollisionResults();

ship.collideWith(ray, results);

if (results.size() > 0)
CollisionResult closest = results.getClosestCollision();

Vector3f pos = closest.getGeometry().getWorldTranslation();

ship.attachChild(makeCube("noname", pos.getX() , pos.getY(), pos.getZ()));
// this line adds a cube in the parents cords not the child who got hit whit the ray :(

protected Geometry makeCube(String name, float x, float y, float z)
Box box = new Box(new Vector3f(x, y, z), 0.5f, 0.5f, 0.5f);
Geometry cube = new Geometry(name, box);
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
mat1.setColor("m_Color", ColorRGBA.randomColor());
return cube;


I’m rusty as hell since I’ve been away for a bit, but try changing:

[java]Vector3f pos = closest.getGeometry().getWorldTranslation();[/java]


[java]Vector3f pos = closest.getGeometry().getLocalTranslation();[/java]

for starters. I’m so rusty at this though that even I feel like this probably isn’t it… but I figured I’d take a stab. Apologies in advance if I’m right on being wrong :stuck_out_tongue:



All of your children are located at the same coordinate as your ship. They just happen to have mesh data that is offset. Leave the Box meshes at 0,0,0 and then translate the Geometry nodes relative to the ship instead.

1 Like