Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm working on a physics driven game using a java port of Bullet (JBullet).

In our game we have a ball that can have collisions with the other objects, including the objects that define the boundaries of the playing area.

Since we consider collisions between the ball and other objects as a very important aspect of the gameplay we wish to handle those collisions in our own code. This allows us to get non-realistic but very controllable behavior for the ball.

The other gameobjects also collide with each other, but JBullet handles those collisions well and we have no issues there.

The problem is that we have great difficulty triggering the custom behavior in the correct way. In our first set-up called our custom collision handling code every time JBullet reported a collision for the ball. This caused undesired behavior as a single hit could trigger multiple reported collisions. Which caused the ball to be sort of glued to the wall.

Our "fix" for this was to have the ball keep a timer and to ignore subsequent collisions occurring within let say 0.1 second of another. However, this caused ball to bounce through walls in some cases, probably because the first reported collision isn't the one we expect, and the ball-wall collision occurring shortly after is sadly ignored.

So that brings me to my question. How does one sort this out without resorting to all sort of "fixes" that only make the problem more complicated and less predictable?

Would for instance placing the ball at the last known position before the collision and handling the collision from there work? But what if another object has moved to that position in the mean time.

Or maybe calculate future collisions with the ball for non-moving objects and enforcing them if they are missed by the physics?

Any feedback / thoughts / revelations would be greatly appreciated!

share|improve this question
    
Can you provide some samples of your code? –  ashes999 Sep 2 '11 at 12:47
    
What part of the code are your particularly interested in? I think two JBullet call-backs are of interest here, the near-call back which is called when objects are close. And the handleCollision method. In the near call back near objects are ignored if the timer is too low. In the handleCollision the angle of reflection is set to the negative of the angle of incidence. –  thomasD Sep 2 '11 at 12:57

1 Answer 1

up vote 2 down vote accepted

About objects sticking to one another, that is a classic flaw in impulse physics simulation engines, it happens when two objects haven't cleared each other completely after a collision, the collision formula will then shift them back to move towards one another, and they will stick to this pattern until something disturbs it. The simplest way to deal with this problem is to check if the two objects are actually moving towards one another, if not, don't respond to the collision.

As for using custom handling on top of a prebuilt library, beware about it, when you open the black box you will have to understand what goes on inside it in order to be sure that you don't break anything. In some cases rolling your own physics could be a better alternative, you would certainly gain a lot of useful knowledge for tinkering with physics this way.

share|improve this answer
    
The normal trick did fix most of the problems, thanks. Multiple collisions still occur in some occasions, but other than causing the sound effects to loop they have no effect. I guess I still need a timeout for sound and visual effects only. As for doing all the physics manually, I would love to, but I don't think it would fit in our time schedule. Again, thanks! –  thomasD Sep 4 '11 at 12:26
    
Maybe you just need multiple different collision sound effects, if you play the same sound twice at a very short interval it will create some weird interference, but if there is some natural variation between them it will sound naturally like two collisions at a very short interval. They don't have to be distinctively different, there just needs to be some "natural" variation in the exact composition. Of course there should be no sound at one of these skipped collisions either. –  eBusiness Sep 4 '11 at 14:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.