[SOLVED] Removing Nodes / Objects from Root Node... again


I’m trying to remove node / object from rootNode - causing disappearance of consummable crate. And of course everything is OK except the fact, that using crateNode.removefromParent(); makes only visual dissapearance but this area is still collidable and I have no idea how to fix it. I tryed to understand the reason and to find solution in old topics but solutions was unclear.


Or something. You surely have code to add to the physics space, so you have to take care of removing it again.


The crate does not depends of phisics. Is Declared in myApp , initialised in SimpleInitApp as an spatial, and tested in SimpleUpdate…


If it’s not using physics then what does this mean?

        public void simpleInitApp(){
bulletAppState = new BulletAppState();

    crateLifeNode = new Node("crate life node");
    modelCrateLife = assetManager.loadModel("Models/crate/crate.j3o");
    physicsCrateLife = new RigidBodyControl(0f);
    crateLifeNode.setLocalTranslation(new Vector3f(3, 0.5f, -50));

 public void simpleUpdate(float tpf) {

rezultat = new CollisionResults();
BoundingVolume bv = crateLifeNode.getWorldBound();
characterNode.collideWith(bv, rezultat);

if(rezultat.size()>0 )       {


Effect - physicsCrateLife still exists but invisible. I’m struggling with it a long time and have no idea what is the problem.


You add the item to the physics space in this line. You must REMOVE it just like @Darkchaos said.

The scene space and physics space are separate. If you remove a node from the scene it does not remove it from the physics space automatically.


Thanks… but He is referring to node but I have added physics object. I’m afraid I don’t understand the rule.
Ok. I have added physics form of my model in PhysicsSpace,
I’m testing collision between characterNode and BoundingVolume of crate Node. Next step, I remove crate Node but still remains shape in PhysicsSpace. Shape of what? -Of my object attached to cratePhysis or BoundingVolume of crateNode? … well …
but finally line droped by @Darkchaos is flashing red on method getState…


You are doing things wrong here, but first: You are indeed removing the crate (bulletAppState.getPhysicsSpace().remove(physicsCrateLife);).
Two things to consider: For a health popup you probably want a “GhostCollision”, which means physics engine tells you when there is a collision but the medikit itself is a ghost, you can walk through it.

Why not your approach? Well, it could be that the physics engine prevents you from reaching the crate. Even if not, it will make your life more simple, use the right tools for the right problem.

To the code:
Your problem is this: You request a volume from the Node (which is like: (3, 3, 3) with a size of (2, 2, 2)).
Then you collide the player with it. This will always be true. You can do to the node whatever you want, but the bounding volume still exists, because well, that’s where the node would be, visible or not.

So to fix your code, you could set crateLifeNode to null, and if it’s null, don’t check collisions (because obviously there is no Node anymore). Alternatively crateLifeNode.getParent() != null, because then you can keep the Node and just check if it is “visible”/attached.

So the problem is that

BoundingVolume bv = crateLifeNode.getWorldBound();
characterNode.collideWith(bv, rezultat);

Will always be true. It’s like asking when the player will be at (0, 0, 0), the engine will tell you, no matter if there is something visible or not.

So again, the best way would be GhostCollisions there. A third way would be to have a node which contains all crateLifes and then do collideWith with that, then the removed crates aren’t there anymore. But that’s not a good solution.


This advice exhausts the topic. Thank you.