Object removal during game play and collision detection

Hello everyone,

I am having some problems with removing objects mid-game and collision detection dropping out on me. I’ve managed to duplicate the conditions, but I still don’t understand the behavior.

In my game, I have different types of power-ups. When the player runs over the power-ups (which requires collision detection), the power-up is removed from the scene.

Here is the odd part:

For testing purposes, I only have two power-ups in my scene right now. If I run over one (doesn’t matter which), it dissapears as it should and everything seems to be fine. If I run over the second (thus removing all the power-ups from the scene), collision detection for the entire scene stops working. I am able to walk through any surface.

My question is two-fold:

  1. What would be the appropriate set of calls for the removal of a collideable object mid scene?

    Here is what I have now:

public void destroyPowerUp() {
      game.sceneNode.updateGeometricState(game.getTime(), true);

I have also tried updateWorldData(float time) and updateWorldBounds() on the sceneNode, as well as several permutations of all of the above. None seem to work. Any ideas?

2. Why would the removal of one object not cause an issue, but the removal of both cause problems? The power-ups are independent objects. Their only commonalities are that they are both linked to the sceneNode, both stored in an ArrayList in a PowerUpManager class, and both have particle systems attached to a node that does not do collision detection.


I am about to pull my hair out here! In an effort to isolate the problem, I have completely removed all the power-up creation code. When I do this, my ENTIRE collision detection system breaks! I don’t understand how these arbitrary objects could cause such a headache.

I thought I was doing things correctly when I loaded my map, but obviously I’m not. I am loading the map with the following code:

JmeBinaryReader jbr = new JmeBinaryReader();
      jbr.setProperty("texurl", TEXdir);
      jbr.setProperty("bound", "obb");

try {
         i = jbr
               .loadBinaryFormat(new ByteArrayInputStream(BO.toByteArray()));
      } catch (IOException e) {
         System.out.println("darn exceptions:" + e.getMessage());

I *think* this creates the correct bouding volumes that I need. Then I attach this code to a sceneNode like this:


Someone please tell me what I need to update at this point!!! All of these calls are made in simpleInitGame(). sceneNode is attached to rootNode. The collisionModel for the player is created in a similar fasion (also in simpleInitGame).

Do I need to update the geometricState, the worldBounds, the collisionTree, all of the above, some combination of the above? In what order? Is order important?

I am getting desperate here guys. My project is due in a week. I thought it was working, but it has come crashing down in the past few days, and my group members have been somewhat absent (to put it mildly), so help from them is pretty much non-existent. Please help me out here and give me something to get me back on track. Thanks.

I’m not sure if you have to, but did you update the modelbound?

edit] didn’t read it all. Alle collission examples show an update of the modelbound, so i guess you have to set / reset it

When removing and adding items it is important to call updateGeometricState on the root node (as removing an item affects the bounds all up the tree path). However, that being said, I really don’t know why this would create such oddities with regards to collision. I’ll try to get a test case for it and help.

Do you have any test cases yourself? I realize it will take me awhile to get something set up to simulate your circumstances.

mojo, I appreciate the offer to help, and in a few weeks I will go back and address the issue in full to identify the problem (most likely 1-2 lines that are needed somewhere in the mix). Unfortunately, I don’t have the time right now to “fix” the problem. I’ve had to make a hack that basically makes the power-up invisible and inactive, thus I am no longer removing/adding powerups dynamically. This might actually prove to be a better method overall with networking in mind, but regardless, I still want to know what in the hell is going on with the original design.

The thing that really gets me is that, the dynamic adding/removal of objects should be breaking the collision detection in the same way whenever I fire one of the weapons in game. I follow the same basic flow and make the same types of attachments for the creation of a projectile.

At some point, I will post the source code to the game. It is so big right now, that simply describing the design, scene layout and calls I am making would be futile. I suspect an expert eye would be able to spot the problem fairly quickly. Thanks again, and I’ll be back to this problem in a few weeks…after the project deadline…for my own sanity, if nothing else.

I still want to know what in the hell is going on with the original design.

me too.

The thing that really gets me is that, the dynamic adding/removal of objects should be breaking the collision detection in the same way whenever I fire one of the weapons in game. I follow the same basic flow and make the same types of attachments for the creation of a projectile.

Right, in a quick little test case I made, I had no problems, but I can't obtain the same level of complexity that your game has in a short test class.

Are you ready for this?

I figured out what was causing the problem, although I still don’t know why it wasn’t occuring before with the projectile creation/destruction.

I had a skyBox attached to the node upon which collision detection is performed. Unfortunately, there is no bounding volume set up by default for the sky box. If you try to perform a collision detection check b/w two objects attached to one node, ALL objects on that root node must have bounding volumes. I had discovered this behavior a few weeks ago, but in the previous instances, NPE’s had been thrown rather than the collision detection breaking and the game continuing.

So, after many hours and some new grey hairs, I have found the ONE line of code that caused all my grief.

Thanks again mojo for the enthusiasm to help. I really do appreciate it.

Thanks for this, this is an exceptional case that should be caught by the collision detection system as to not cause these errors. I’ll look into how to handle this condition.

I hope my post didn’t come across as accusing jME of the trouble. I look at this as more of a design problem on my part, although I can see (for simplicity’s sake) why all types of geometry should have the appropriate collision detection necessities.

nope, didn’t sound accusing at all. I just want to make sure that no one else runs into this problem as well. So, if it’s something that can be handled within the collision system, great, otherwise I need to make sure it is documented very well.

i’ve just ran into this problem with another case :

the lenslare attached to the node where i check collision,

(lens flare has no model bound)

(i had the null pointer exception thought, so i found quickly enough :wink: )

i fear it could be the same problem with particle if they don’t have model bound set by default.

hope this info will be useful,


Ok, so it’s definately a model bound issue. I’ll take care of it. Thanks.