Spawning multiple sphere physics nodes on death -help

This is a controller which gets attached to the scene when a player dies. Right now it just spawns spheres (in the future they will be coins)



so, the first sphere spawns correctly, however, subsequent spheres dont appear. it seems that their physics representations are there, just not the physical sphere part. that is why i even went to the extent of making a sphere array to match my coin array, which still didnt solve the problem!!



does anyone know an explanation for this problem??






    class coinKeeper extends Controller {
       int number;
       Vector3f location;
       float timekeeper = 1.4f;
       DynamicPhysicsNode[] coins;
       Sphere[] s;



       
        public coinKeeper(int number, Vector3f location) {
            this.location = location;
            this.number = number;
            coins = new DynamicPhysicsNode[number];
            s = new Sphere[number];
      }
        
        

      public void update(float time) {
            if(timekeeper < 2){
            timekeeper = timekeeper + tpf;
            }
            
            if(number == 0){
               scene.removeController(this);
            }else{
               if(timekeeper >= 2){
                  int i = number - 1;
                  s[i] = new Sphere("lol", new Vector3f(), 20,20,3);
                     coins[i] = pSpace.createDynamicNode();
                     coins[i].attachChild(s[i]);
                      coins[i].generatePhysicsGeometry();
                    coins[i].computeMass();
                    coins[i].setMass(.1f);
                      coins[i].setCollisionGroup( playerGroup );
                     coins[i].setLocalTranslation( location );
                     coins[i].setModelBound(new BoundingSphere());
                    coins[i].updateModelBound();
                      coins[i].updateGeometricState(tpf, true);
                     scene.attachChild(coins[i]);
                                     //this simply shoots the coin into the air
                     Coin.Spawn(coins[i]);
                     coins[i].addController(new coinMaster(number));
                     timekeeper = 0;
                     number = number -1;
                }
            }   
         }
    }

I'm not sure where the problem lies here, since I haven't worked with JME Physics, but perhaps try and give the sphere's unique names, instead of them all being called "lol"?



Btw. in your code snippet the ingoing argument to the update method is called time while the value you're adding to timekeeper is named tpf. I'm guessing this isn't so in your actual code though.

hello.



dont worry about the time/tpf discrepency. that tpf is a global tpf variable based off the main games update method "tpf"



i also gave them unique names and that did not fix the problem. i have to leave right now but when i get back i will update you with more information.

Begin iteration: 3
Nov 28, 2009 12:17:28 AM com.jme.scene.Node <init>
INFO: Node created.
Nov 28, 2009 12:17:28 AM com.jmex.physics.impl.ode.OdePhysicsSpace addNode
INFO: PhysicsNode (null) has been added
Nov 28, 2009 12:17:28 AM com.jme.scene.Node attachChild
INFO: Child "Sphere[3]" attached to this node "coins[3]"
Nov 28, 2009 12:17:28 AM com.jmex.physics.PhysicsNode generatePhysicsGeometry
INFO: using default model bound for: Sphere[3] (com.jme.scene.shape.Sphere)
Nov 28, 2009 12:17:28 AM com.jme.scene.Node attachChild
INFO: Child "null" attached to this node "coins[3]"
Nov 28, 2009 12:17:28 AM com.jmex.physics.impl.ode.OdePhysicsSpace removeNode
INFO: PhysicsObject (coins[3]) has been removed from PhysicsWorld and will no longer take place in the simulation
Nov 28, 2009 12:17:28 AM com.jmex.physics.impl.ode.OdePhysicsSpace addNode
INFO: PhysicsNode (coins[3]) has been added
Nov 28, 2009 12:17:28 AM com.jme.scene.Node attachChild
INFO: Child "coins[3]" attached to this node "scene"
2
End iteration: 3



this happens when running simply this code:

               if(timekeeper >= 2){

                  System.out.println("Begin iteration: " + iteration);
                  int i = number - 1;
                  String name ="Sphere[" + i+"]";
                  s[i] = new Sphere(name, new Vector3f(), 20,20,3);
                     coins[i] = pSpace.createDynamicNode();
                     String name2 ="coins["+i+"]";
                     coins[i].setName(name2);
                     coins[i].attachChild(s[i]);
                      coins[i].generatePhysicsGeometry();
                    coins[i].computeMass();
                    coins[i].setMass(.1f);
                      coins[i].setCollisionGroup( playerGroup );
                     coins[i].setLocalTranslation( location );
                     coins[i].setModelBound(new BoundingSphere());
                    coins[i].updateModelBound();
                      coins[i].updateGeometricState(tpf, true);
                     scene.attachChild(coins[i]);
                     Coin.Spawn(coins[i]);
                     //coins[i].addController(new coinMaster(number));
                  // System.out.println(coins[0]);
                  // System.out.println(coins[1].getTriangleCount());
                  // System.out.println(coins[2].getTriangleCount());
                  //System.out.println(i);
                  // System.out.println(coins[i].getTriangleCount());
                     timekeeper = 0;
                     number = number -1;
                  System.out.println("End iteration: " + iteration);
                     iteration = iteration+1;



This seems very interesting to me. Why does it remove my coins from the physics environment, simply to reattach it again? I think this is what is causing, or may be, my problem.. except I am at a loss for how to isolate it.

Also, the Coins.Spawn(coins) is simply

      int X_OFFSET = randomgen();
      int Z_OFFSET = randomgen();
      Vector3f force = new Vector3f(X_OFFSET, 400, Z_OFFSET );
      coin.addForce(force);



the name is not what it does.. heh.

Any thoughts or comments?

EDIT:: FIXED
what the problem was location was being set to the location of each ball, and they were all ontop of eachother.

instead of saying coins.setLocalTranslation(location);
i needed to sat coins.getLocalTranslation().set(location);  whatever the difference is.. i dont know. but it works now :)

its important to know the difference.



sphere.setLocalTranslation(vector); this sets only the reference, if you change 'vector' later, you also change the sphere's translation.



sphere.getLocalTranslation.set(vector);  this makes a copy, you can safely change 'vector' later.