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");
rootNode.attachChild(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());
cube.setMaterial(mat1);
return cube;
}