Advertisement

Bullet Physics Detecting Collision

Started by June 16, 2013 05:54 PM
4 comments, last by Krohm 11 years, 8 months ago

I'm trying to figure out how to detect a collision between two objects. To be more specific, a collision between the players sword and the beasties. I've already looked around the internet and although I've found a lot of information, I don't understand most of it. I've come here hoping someone can enlighten me and correct me if what I'm trying to do is incorrect.

Even though I don't have much knowledge with bullet physics regarding collision detection, but I have a pretty clear idea of what I'm trying to achieve. My idea is simple: program the monster class so that each of its instances keeps track of what it is colliding with. If it collides with the player's sword then the appropriate actions are taken. My main concern is whether or not I can apply collision detection via individual rigid bodies.

In terms of code, I would imagine the collision detection as some sort of independent callback function which would take the two colliding objects as parameters and if there was a collision between said objects, it would return true.

I hope I'm being clear, but I'm not sure how else to explain. Basically, object01 collides with object02 and Bullet goes, "Hey, guess what...".

Aluthreney -- the King of sheep.

There are no real callbacks. I don't remember if there is a way to detect collision between 2 bodies either.

General approach is to call stepSimulation() normally, and just check if it collided. It's pretty long code, so just take a look at wiki: http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers

Advertisement


To be more specific, a collision between the players sword and the beasties.

Do you really need physics for that?

Can't you just check the distance and view cone between player and beasties when sword is triggered for swinging?

There are no real callbacks. I don't remember if there is a way to detect collision between 2 bodies either.

General approach is to call stepSimulation() normally, and just check if it collided. It's pretty long code, so just take a look at wiki: http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers

Thank you for the reply.

I've already looked at that page, but it didn't offer any insight as to what's going on in the code. If you understand could you please shed some light or offer another link to a page that explains it in more detail?

In the meantime, I'll keep looking.

Aluthreney -- the King of sheep.

There are no real callbacks. I don't remember if there is a way to detect collision between 2 bodies either.

General approach is to call stepSimulation() normally, and just check if it collided. It's pretty long code, so just take a look at wiki: http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers


To be more specific, a collision between the players sword and the beasties.

Do you really need physics for that?

Can't you just check the distance and view cone between player and beasties when sword is triggered for swinging?

Forgive me. It seems I've looked at this the wrong way. I thought physics libraries, like Bullet, took care of collision detection as well as...physics. I assumed they were both on the same pedestal. I guess I was wrong.

Thank you for the reply.

Aluthreney -- the King of sheep.

You are correct instead.

Bullet and most physics library can do collision only if you tell them to do so.

And this is because

  1. collision is a prerequisite for dynamics
  2. collision produces a lot of results which are useful for dynamics

So long story short: it really make sense to have the two things tightly coupled.

I'd suggest against using the purely collision world (with no dynamics). Dynamics really come at very low cost if you're not using them.


My main concern is whether or not I can apply collision detection via individual rigid bodies.
What does that mean? You can check if an object collides with another using btCollisionWorld::contactTest. You don't even need the object being tested to be in the world.

Previously "Krohm"

This topic is closed to new replies.

Advertisement