Check collision between two objects

Hey,



I’d like to check the collision between two objects to trigger an action then. I’ve done the HelloPicking tutorial but I can’t really link this to my problem as in my case the collision is already detected by collision shape (I guess). Actually I’d like to make a cube disappear when a ball roll over it. So far I have the ball and the cube with their relative collision shapes :).



If someone could help me out with this. Thx !

You can check the thread I posted a few days ago with the same question

http://hub.jmonkeyengine.org/groups/physics/forum/topic/character-enemy-collision-with-player/

In short the Cube and Ball need to have a CollisionShape and you need to have a PhysicsCollisionListener with a

public void collision(PhysicsCollisionEvent event) {}

This method will be triggered whenever there is a collision

Look at TestCollisionListener in the test repo

Google Code Archive - Long-term storage for Google Code Project Hosting.



EDIT : and these docs btw

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics_listeners

2 Likes

Overriding the collision method seems to be what I look for but it seems it would imply that my two objects are physical which is not the case :frowning: cause i actually want my ball to pass through the cube without any impact or reflection force to be made. So maybe there is a way to override collision method removing physical interactions, am I right ?

I overrided the collision method and all works nice except a thing. When my ball roll over the box, my box disappear, the return is good (a print for now) but it seems that the BoxCollisionShape is still present blocking my ball. What I trigger when the collision is detected is :


  • I attach the box to another node (a “garbage” one put far away)
  • I move the Geometry of the box to the garbage node
  • I move the bow node to the garbage node



    Despite all this, my ball is still hurting something invisible (which i guess is my CollisionShape). Isn’t the CollisionShape supposed to stick with the Geometry ?

Just as you add stuff to the physics space you have to remove it too. You can also setEnabled(false) the control, that removes the physics object too.

It works, thx !

@ said: You can check the thread I posted a few days ago with the same question<br /> http://hub.jmonkeyengine.org/groups/physics/forum/topic/character-enemy-collision-with-player/<br /> In short the Cube and Ball need to have a CollisionShape and you need to have a PhysicsCollisionListener with a<br /> public void collision(PhysicsCollisionEvent event) {}<br /> This method will be triggered whenever there is a collision
@rakesh8015 said:

Has you account been hacked? Your last two posts are just quoting a previous post with no additional information.