Easy way to throw flag/signal on geometry intersection/collision?

Hi,



I’m trying to port over an application from Panda3D to jMonkey. Basically I need to figure out how to implement the following:


  • When two random geometries intersect a flag is thrown (ie bool set to 1)
  • After they stop intersecting the flag is turned off (ie. bool set to 0)



    I don’t need reactive physics on the geometries, I just need to know whether they are intersecting. I’ve looked through a few tutorials, however, some do not appear to reflect the recent changes to jMonkey’s bullet integration.



    Anyway, is there an easy way to detect when two geometries intersect/collide? I was reading the JavaDoc and found Interface PhysicsCollisionListener. Is this what I’m looking for? If so, are there any tutorials/examples which demonstrate this feature? If not… being pointed in the right direction would be greatly appreciated.



    Thanks!

I just noticed I placed this question in the wrong forum. Can someone move it to the physics troubleshooting forum?

It is PhysicsCollisionListener and theres an example in jme3test.bullet.TestCollisionListener.java

Thanks Norm, I figured out the collision handling. I’m unable to find how to let objects pass through each other and yet still throw a flag when they intersect. I don’t need them to react to physics but instead indicate when they are intersecting. I’ve been looking through jBullets collision documentation and I can’t seem to find a way to do this. Is it even possible to do this within jBullet? One of the jMonkey tutorials state the following:


However you must be very careful not to cause an “impossible state” where one physical object overlaps with another! Within the game, you typically use the setters shown here exclusively.


Should I even be using bullet for this? Am I going about this the wrong way?

You could use the PhysicsCollisionGroupListener for that.

I can’t seem to get the grouplistener to detect a collision without causing reaction physics. I can set objects to different masks to have them pass through each other but that doesn’t throw a collision.

Try returning false :stuck_out_tongue:

in public boolean collide?

This seems to work. However i’m confused… Don’t I want to pull at my node checking in public void collision rather than collide, like the tutorial does?



http://pastie.org/1494325

Well it cannot work because it works with collisions which you try to prevent. No collision, no CollisionEvent.

Hrm… ok. I’ll have to play around with this now to see if I can get it to do what I want. Thanks for the help!

Ok so now that I can detect objects hitting, what is the best way to check if they are no longer colliding? Should I add the collided objects to an array that counts down and then checks if the two nodes are still colliding? Is there a better way then that built in to bullet?

As a physics tick listener you will be called at the frequency of the actual physics steps and you could check if you got any collisions from that specific object in the previous step. But I guess doing a ray check after the collision happened should work as well, checking if you still collide with that object abed on your location and the collision location, depends on what you want to do.

Alright. Say I want a timer to start counting down when one object enters another. While the object is inside it continues to count, if it exits the timer is reset (or destroyed). If the objects still intersect when the timer reaches zero, lets say an explosion animation is triggered. I don’t mind if the collision isn’t completely exact, so I suppose ray checking isn’t necessary. If I plan on having more than one object would it make sense to do the following?


  1. Create a map that is keyed to nodeID’s
  2. When an object intersects spawn a thread with a timer
  3. Place the nodeID and threadID into the map
  4. remove key from map if timer reach zero or objects stop intersecting.



    Does jMonkey have something like a task/event manager for this type of thing?



    (edit: If jMonkey doesn’t have that it looks like java’s has a timer/actionlistener class

    http://download.oracle.com/javase/1.5.0/docs/api/javax/swing/Timer.html )

Yeah, but just increment some internal float variable with tpf and you have an accurate and more importantly thread-free timer :wink:

Thanks. Is there a better way to get the name of a node within collide besides node.getUserObject().toString()? The user-object name includes “node (Physics Node)” rather than the .getName for collision which does “node”.

I dont understand, the getUserObject() returns the Spatial the PhysicsControl is attached to.

In one of the collision demos, event.getNodeA().getName() is called in voide collision. This returns the name of the node so it can be compared to the string “box”,"bullet, or “mesh”. However, since I am unable to use void collision, since collide is false, I need to do those comparisons in boolean collide. Since collide is not passed an event, I need a way to get the names of the object to compare like in collision. As it stands, when i use nodeA.getUserObject().toString(). I get the name + (PhysicsObject). Maybe this is because the tutorial still uses the old PhysicsNode way to create a collision object? I’ll change it to the new way and see if this occurs.

Here is the code from what I’m talking about. http://pastie.org/1497286 . Essentially I want to get it to return the name of the passed node without the object identifier (ie Node or Geometry)

The getUserObject() returns the Spatial the PhysicsControl is attached to, before it was a physics node, now its the Geometry directly.