ok im still new to jme3 and as i go ive been trying to keep track and document my experience learning so hopefully it could be of help to others,
the current issue ive come across is exactly how do i populate my level with items like sonics rings or marios coins?
ive made a quick method for creating and using my models that are to be static, non moving, i give to it the model its to load, its scale and xyz co ordinates
[java]public void mesh(AssetManager assetManager,String model, float scale, float locX,float locY, float locZ) //pass model mesh, scale in world, and x y z position in world
{
mesh = assetManager.loadModel(model); //loads 3d mesh
mesh.setLocalTranslation(locX + i , locY, locZ); //sets position
mesh.setLocalScale(scale); //sets scale
crateNode = new Node();
crateNode.attachChild(mesh);
smash = new AudioNode(assetManager, “Sounds/Boxbreak.WAV”, false);
smash.attachChild(mesh);
smash.setLooping(false);
smash.setVolume(0.2f);
smash.setPositional(true);
smash.setLocalTranslation(mesh.getLocalTranslation());
crateNode = new Node();
crateNode.attachChild(mesh);
rootNode.attachChild(crateNode);
}[/java]
in simpleinitapp() i just type mesh(assetManager,“where/ever/model/is.j3o”,2,10,0,10);
i also have a collision check method that will check for a collision with my player (a car node) and the crateNode to my mesh,
[java]private void colCheck(Node a, Node b)
{
CollisionResults results = new CollisionResults(); //creates new collision results
BoundingVolume geomBounding = b.getWorldBound(); //creates bounding volume from car chasis for testing collision
a.collideWith(geomBounding, results); //check collision, spatial must be first and volume after ie spatial.collideWith(boundingVolume, results);
if (results.size() != 18)
{
if(i != 0)
{
i = 0;
}
}
if (results.size() >= 18 && results.size() < 19) //if theres a collision results bigger than 0 do whats inside brackets
{
System.out.println("Number of Collisions between" +
a.getName()+ " and " + b.getName() + ": " + results.size());
CollisionResult closest = results.getClosestCollision(); //get closest collision resultd for further collision testing
if(closest.getDistance() <= 0 )
{
if(closest.getGeometry().getName().equals("crate"))
{
System.out.println("its a crate");
if(i != 1) //on first collision detection i = 0 whats in this loop runs, and i becomes = to 0, for all other collisions detected that are unneeded whats in here wont run again
{
crateNode.detachChild(mesh); // remove crate node from visibility
smash.play();
// bulletAppState.getPhysicsSpace().remove(rigA); //remove its body so an invisible force wont remain
++number; // increases box count by 1
hudText.setText("Boxes Broken: " + number);
++i;
}
}
if(closest.getGeometry().getName().equals("life"))
{
System.out.println("its a life");
if(i != 1) //on first collision detection i = 0 whats in this loop runs, and i becomes = to 0, for all other collisions detected that are unneeded whats in here wont run again
{
crateNode.detachChild(mesh); // remove crate node from visibility
smash.play();
// bulletAppState.getPhysicsSpace().remove(rigA); //remove its body so an invisible force wont remain
++number; // increases box count by 1
hudText.setText("Boxes Broken: " + number);
++i;
}
}
}
}
else
{
// i=0;
}
} [/java]
i have it working with 1 box and depending on what model ive set to be my mesh it will do different things if i want it to like raise a counter or lower it, but my issue is how do i populate my game with a bunch of boxes coins or rings or items of such, i can get 1 object loaded and trying
[java]mesh(“model 1”,1,10,0,10);
mesh(“model 2”,1,20,0,10);
mesh(“model 3”,1,30,0,10);
mesh(“model 4”,1,40,0,10);[/java]
doesnt work, it will only recognise collision with mesh(“model 4”,1,40,0,10) and none of the others, so how do i populate the world? ive spent a week looking up the forum with no luck and cant find any videos or tutorials highlighting this particular topic. any help is appreciated and i thank the developers for such a great game engine.