Detaching nodes and collisions

Hello everyone! I'm trying to make a simple golf game and I'm having some problems with collisions.



I put a flag in the place where the hole is, but I need to detach this node when the player gets near the hole area.

I detach the flag node from the scene, but objects still collide with it (even though it doesn't render).



I guess I'm missing something here, but I've tried everything and have no more ideas.

Does anybody know what can I do to fix this?



Thanks!!

you also need to remove the node from the physics world, only detaching it from the scene is not enough.

try physicsnode.setActive(false).

Thanks core, i tried what you suggested but the problem remains.

I've also tried setActive(false) on all the children of the node and even the parent. I've even detached them all and still have invisible but collidable objects  :?



Do you know any workaround that may work?

It should work.


I've also tried setActive(false) on all the children of the node and even the parent

Do you attach different PhysicsNodes to each other? i think that's not supported (not quite sure though). Better only attach physicNode to Nodes not other PhysicNodes.

Pressing SPACE lets the small box fall through the floor.


public class TestSimplePhysics extends SimplePhysicsGame {
   private StaticPhysicsNode floor;

   @Override
   protected void simpleInitGame() {
      /* create the floor */
      Box b = new Box("floor", new Vector3f(), 100, 100, 1);
      b.setModelBound(new BoundingBox());
      b.updateModelBound();
      b.getLocalRotation().multLocal(new Quaternion().fromAngleAxis(FastMath.DEG_TO_RAD*90, Vector3f.UNIT_X));
      floor = getPhysicsSpace().createStaticNode();
      floor.attachChild(b);
      floor.generatePhysicsGeometry();
      floor.getLocalTranslation().y -= 2;
      rootNode.attachChild(floor);
      
      /* add another Box */
      b = new Box("floor", new Vector3f(), 1, 1, 1);
      b.setModelBound(new BoundingBox());
      b.updateModelBound();
      DynamicPhysicsNode box = getPhysicsSpace().createDynamicNode();
      box.attachChild(b);
      box.generatePhysicsGeometry();
      box.getLocalTranslation().y += 10;
      rootNode.attachChild(box);
      
      // set up a key to remove the floor
      KeyBindingManager.getKeyBindingManager().add("remove_floor", KeyInput.KEY_SPACE);
   }
   
   @Override
   protected void simpleUpdate() {
      super.simpleUpdate();
      if (KeyBindingManager.getKeyBindingManager().isValidCommand("remove_floor", false) == true) {
         // remove from physics world
         floor.setActive(false);
         // remove from visual scene
         floor.removeFromParent();
      }
   }
   public static void main(String[] args) {
      TestSimplePhysics game = new TestSimplePhysics();
      game.setConfigShowMode(ConfigShowMode.AlwaysShow);
      game.start();
   }
}


Thanks core! I think I'm messing things up by attaching physics nodes to each other as you say. I'll try to fix my scene graph and see what happens.

Thanks a LOT for your help!!!  :smiley: