@Override
    public void collision(PhysicsCollisionEvent event) {
        Spatial nodeA = event.getNodeA();
        Spatial nodeB = event.getNodeB();
        
        String nameA = nodeA == null ? "" : nodeA.getName();
        String nameB = nodeB == null ? "" : nodeB.getName();
        
        if(nameA.equals("player") && nameB.startsWith("pickUp")) {
            GhostControl pickUpControl = nodeB.getControl(GhostControl.class);
            if(pickUpControl != null && pickUpControl.isEnabled()) {
                pickUpControl.setEnabled(false);
                nodeB.removeFromParent();
                nodeB.setLocalScale(0.0f);
                score += 1;
                if(score >= PICKUP_COUNT) {
                    messageText.setLocalScale(1.0f);
                }
            }
        } else if(nameA.startsWith("pickUp") && nameB.equals("player")) {
            GhostControl pickUpControl = nodeA.getControl(GhostControl.class);
            if(pickUpControl != null && pickUpControl.isEnabled()) {
                pickUpControl.setEnabled(false);
                nodeA.setLocalScale(0.0f);
                score += 1;
                if(score >= PICKUP_COUNT) {
                    messageText.setLocalScale(1.0f);
                }
            }
        }
    }
Physics based marble game.

@author SkidRunner (Mark E. Picknell)
jme3-examples/src/main/java/jme3test/games/RollingTheMonkey.java