Make objects disappear when "walking into them"


I’m kind of new to jmonkey but I’ve done all the 13 first beginner tutorials but I’m still wondering something.

In my game, I want a character which is suppose to collect stuff to get points. In the same way Sonic collects the gold rings. So I want to put the stuff (which is suppose to be collected) into the terrain in the scene composer, which is not a problem.

The problem is that I do not know how to make them disapperar when the character “walks into them”. Should they have some kind of physics like rigidbody och charactercontrol or what should I do?

// Thanks

1 Like

You can try detaching them from the rootNode or the parent node they have. That should work.


That is what I’m planning to do, but I do not understand how I am supposed to detect the actual collision.

Thanks for replying :slight_smile:

Have you checked out ?

Use the link @DannyJo provided. using ray or bounding boxes, that way you don’t have to use Bullet. That is depending on your project’s approach.

If you are using physics already you need to go a bit more advanced since it’e best to use Bullet collision listeners and stay with one way

Oh I thought I linked the other wiki page about collisions using Collidable with bounding boxes etc. as the OP mention he’d already gone through all the tutorials and this is a bit of an advanced extra topic :smiley:

Ooops, sorry :stuck_out_tongue: I had many tabs since I was doing some bullet tests and I got mixed up.

Or if the object are simple enough and you don’t acutally need any fancy collision (like the coins in mario or something like that) and your character should be able to walk through them, you could simply check the distance of the player position to the coin position.

Hello, thanks for answer!

No I haven’t yet, only the beginner tutorials. But I use a tree (included in testdata) for testing so I add the tree in the scene composer. And when I do that, I can collide with the tree. But I don’t want the tree to be a “physical object” (Like it wasn’t there, since I want my character to be able to just walk right into the object, and then it will disappear. Of course I will use something else than tree but i need something to test on :stuck_out_tongue:

Hi and thanks for answering!

Of cource that’s is one idea! But if I go with that, do I need to loop through all the “collectable objects” and check the distance in the update loop?

Yeah that’s what you would probably want to do. Just check if distance < threshold in your update loop.

Ok. But now when I added the tree from the jme3testdata package, I can collide with it. I added it from the scene explorer so I didn’t add any physics to it myself, did Jmonkey do it automatically? How do I remove it?

One more question, what is a “fancier” way of doing collision test with objects like the “gold rings” in Sonic? :stuck_out_tongue:

Sonic definitely doesn’t do more than checking the distance.


Haha okey :stuck_out_tongue: But how do I remove the physics from an object I added in from the scene explorer? I know how to access it in code but I don’t know what to do from here. How could I achieve the same as in Sonic without checking the distance? Is there a fancier way? :stuck_out_tongue:

Thanks for answering!

There is no physics collision shapes added automatically. And definitely not added to the physics space automatically.

I am probably explaing things badly.

In my scene explorer I have a node. Inside the node I have the terrain, the TREE, and ambient light.
I create a rigidbodycontrol for the scene when i load it, and then I also collide with the tree.

So attach your scene to another node and add the rigidbody there.

I think I will go with that. But still, can I detect collision in another way than looping through all the objects in the update loop and checking the distance?

Thanks for great advices!

Of course but its really the simplest and least CPU intense way. What do you think a physics collision system does?

If you’re using bullet take a look at CollisionListener.