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 have been looking into box2d (in java with libgdx) lately and have been trying to create my own custom bounce effect (I increase the Restitution after the first bounce)

To do this as a test I simply checked the location of the object and waited for the first bounce.

But now I wanted to actually implement this and came across a problem: How to detect the collision of 2 specific object in box2d?

I found this tutorial: box2d collision detection - but I am very reluctant to use that code. There must be a simpler and cleaner way to detect a collision between 2 objects (without having to set user data and checking all collisions with giant if() conditions...)

Can anyone help me out? (assuming I am not just hopeful and there actually is a better way)

Help is greatly appreciated

Thanks, Jason

share|improve this question
    
In the C++ version, there exist contact callbacks for this exact purpose. Are those not in the Flash port? –  Clairvoire Sep 17 '11 at 2:43
    
Its a Java port and as far as I can tell there is only one general contact listener where you get all contacts that happened –  Jason Sep 18 '11 at 5:37
    
possible duplicate of how to ignore physics collision of some objects in box2d –  Sean Middleditch Mar 8 '13 at 4:32

3 Answers 3

up vote 3 down vote accepted

I think ultimately you will have to use user data but you can greatly reduce the number of collisions to check with collision filtering.

share|improve this answer
1  
Collision filtering has some other use, it just asks if collision between two objects should be checked or not. if you filter collisions they don't collide at all, not that box2d doesn't give a report for some collisions –  Ali.S Sep 16 '11 at 19:26
    
Yea I guess this is the only way - Thanks for the tip on filtering :) –  Jason Sep 16 '11 at 20:27

Have you tried this editor and its FixtureAtlas? If not, try it out. It automates several steps to make this work.

share|improve this answer

Add a trigger either to your moving ball or to the ground. A trigger is an volume causing some custom game action. Like reaching the end of the level or if a switch can be activated etc.

Your trigger class should know which objects caused the trigger to fire and can do the actual bouncing. Not sure how to do this with box2D though.

share|improve this answer
1  
Yea the box2d part is the problem - never mind ill use UserData I'll just try to make it nice with filtering and better code writing then in the demo. Thanks –  Jason Sep 16 '11 at 20:26

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.