JBullet: How to detect the first contact/hit and play sound?

Let’s face it: projects which use Bullet are mostly simulations.

Seriously, search “Bullet physics” on YouTube and most of the search results will be videos of physics simulations (500K wooden planks vs rolling ball, voronoi shatter, ball vs brick wall…you get the idea). I intend to use the library (or more specifically, the Java port of the library) in my 3D game.

Just wondering, how many of you actually use jBullet in game projects? I’m curious to know if it suits my needs. Right now, game physics is my biggest hurdle, and I’m struggling to figure out how I’m supposed to, say, play a sound when something lands on the floor.

Bullet has a collision callback, but the collision callback is called for as long as the object is in contact with another object, instead of being called when the object FIRST collides with another object. This means that if I use the collision callback to play impact sounds, the sounds will be played repeatedly for as long as the object is in contact with the other object.

Of course, there are workarounds, but it’d be incredibly messy and I want to avoid that. Are there any Bullet wizards here? I need a little help, maybe just a nudge in the right direction. Thanks in advance.

tl;dr it’s difficult to use Bullet to write something other than a simulation. I need to play collision sounds. Help?

I don’t understand the problem… this is what programming is all about: taking something low-level and transforming it into something high-level. Why would this workaround feature be messy by definition? That’s for you to design.

I think your thread’s title/summary is misnamed, because you of course do want a physics “simulation.”
You want to simulate the physics in an interactive game as opposed to simulate the physics in a non-interactive preset scene/setup (which may only seem non-interactive in certain mentioned videos because you were viewing it in a video and because the video rendering was likely produced with slow raytracing).

So the only thing you want to add to that simulation is to detect the first hit to play a sound effect.

So I think your title should say: “JBullet: How to detect the first contact/hit and play sound?”
Maybe that’ll attract more people to solving your problem.

Yep, you’re right. I just changed the title, thanks :slight_smile:

You’re right, I get where you’re coming from. However, Bullet is such a popular and widely-used library that I figured there would be some kind of special collision callback that’s only called the first time instead of being called repeatedly. If such a function does exist in the library, it would be rather pointless to write extra code on my end to do the same thing.