[SOLVED] Getting if a node hit the floor

I have implemented collision listener, it works great. But how to detect this:


if my node hits the floor {

     remove it from scene
     createExplosion();
}



I already tryed getNodeA/getNodeB but it does not work! Help?

Well, the fact that you receive a CollisionEvent means that a collision happened. Now you just have to check the name of the nodes that collided (getNodeA/getNodeB) to know which ones it were. Look at the TestPhysicsVehicle class in jbullet-jme, there is a check if the car collided with the sphere.

What works great? What does not work? What are you doing? If you successfully receive CollisionEvents (as it seems when you're calling getNodeA/B) you could compare the names of the nodes to find out if the floor and node collided here.

an, it receives the information that something collided (This works). But I don't know how to detect if the node hits something (This I don't know).



What I want to do:


  • If the node A hits something:

    – Detach it from root node

    – call method createExplosion()



    Just that. But the problem is I don't know how to compare if myNode has collided if something.

Okay, just a question:



What defines who's the NodeA and who's the NodeB?

Like NodeA is the falling node and the NodeB is the floor?

all spatials have setname getname, so name your grenade "grenade" and your floor "floor" , then fi you detect that one of the nodes is named grenade the other floor, cast the grenade node to your grenadeobject and call explode

GustavoBorba said:

Okay, just a question:
What defines who's the NodeA and who's the NodeB?
Like NodeA is the falling node and the NodeB is the floor?

Its not defined. Mostly its dependent on the order in which you attach them to the PhysicsSpace but different broadphase types can also alter that. But anyway it does not matter.

But I have this code:


public void collision(CollisionEvent e) {
        if(e.getNodeA().equals(physicsTube) && e.getAppliedImpulse() > 18) {
            rootNode.detachChildNamed("Missile");
            createExplosion();
        }
        else if(e.getNodeB().equals(physicsTube) && e.getAppliedImpulse() > 18){
            rootNode.detachChildNamed("Missile");
            createExplosion();
        }
    }



and nothing happens. (P.S: I already tested the amplitude, it gave me 19.0, that's why I'm using 18. And if I removes it, stills the same)

so when nothing happens maybe your createExplosion does not work? how is it supposed to know where the explosion happens anyway? you dont seem to supply any vector for that.

No! You helped me with the eplosion normen (: And it works! It works without beaing called inside CollisionListener. It creates beattiful particles. At 50, 1, 50 (X, Z, Y).



Solved, thank you normen.