"detachChild()" doesn't remove a spatial from collision list?

… a little "push" again…  :wink:



You are checking collisions for objects you've placed in a hashmap. Yet, you never remove objects from the hashmap. That is, you are check every block of the level object's blocks map, but never remove that reference once you remove it from the scene.

Here is a very sloppy fix, to show what I mean:


Set<String> set = level.blocks.keySet();
            String[] keys = new String[set.size()];
            set.toArray(keys);
            for ( int i = 0; i < keys.length; i++) {
                String blockName = keys[i];
                Block block = level.blocks.get(blockName);
                if (ball.hasCollision(block, false)) {
                    ball.direction.z = -ball.direction.z;
                    newPosBall = ball.getNextPosition(tpf);
                    ball.lastCollisionTime = timer.getTimeInSeconds();
                   
                    // TODO: Hmm, is this really the right method to get rid
                    // of the collisions? (detachChild isn't enough..)
                    scene.detachChild(block);
                    level.blocks.remove(blockName);
                }
            }

looking at it now…

mojomonk said:



You are checking collisions for objects you've placed in a hashmap. Yet, you never remove objects from the hashmap. That is, you are check every block of the level object's blocks map, but never remove that reference once you remove it from the scene.

Here is a very sloppy fix, to show what I mean:


Set<String> set = level.blocks.keySet();
            String[] keys = new String[set.size()];
            set.toArray(keys);
            for ( int i = 0; i < keys.length; i++) {
                String blockName = keys[i];
                Block block = level.blocks.get(blockName);
                if (ball.hasCollision(block, false)) {
                    ball.direction.z = -ball.direction.z;
                    newPosBall = ball.getNextPosition(tpf);
                    ball.lastCollisionTime = timer.getTimeInSeconds();
                   
                    // TODO: Hmm, is this really the right method to get rid
                    // of the collisions? (detachChild isn't enough..)
                    scene.detachChild(block);
                    level.blocks.remove(blockName);
                }
            }




Ohhhhhh yeah.... (sigh)
You're right, thanks!
I should remove the objects from the hashmap of course.... but...

Why does

CollisionTreeManager.getInstance ().removeCollisionTree (block);

not work?

It's clear that I should remove the objects from the hashmap in the first place, but
removing them from the collision tree should have done the trick, too?

The loop would check boxes which aren't there any more (not goot) but they should
have been removed from the collision tree.. hence: no collision?

Because a check of collision will add the mesh to the manager when it's needed. Thus, you remove it from the manager, then explicitly check for collisions on the block. The block's bounding volume is determined to be collided and triggers the manager to determine if a triangle collision is hit (which rebuilds a CollisionTree for that block). So, in other words, Spatial's collision/picking methods make calls into the manager that generate a new tree as needed.

Oh my god… long time no see.



Just started (again) with JME, looking at my code (and switching

over to JME 1.0 of course).



Just wanted to say "thanks"… you are right of course, runs fine now if

I remove the block from my HashMap instance.