Box2D Forums

It is currently Thu May 23, 2013 4:13 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue May 01, 2012 4:03 pm 
Offline

Joined: Tue May 01, 2012 3:45 pm
Posts: 7
Hey guys, I'm working on a 2d platformer and running into a problem with bullets/body forces.

Basically what I want to do is still detect collisions between bullet/players (so that the bullet can be deleted/health can be detracted, etc), although not apply the force. Is there any way to do this? I'm not sure collision filtering would work in this case.

Sorry if the solution is simple (or I'm just not fully up to date on box2d's features), but this is really bothering me.

Thanks guys.


Top
 Profile  
 
PostPosted: Tue May 01, 2012 7:19 pm 
Offline

Joined: Fri Apr 13, 2012 7:07 pm
Posts: 3
i successfully handled this with the ContactFilter. basically, i check to make sure one of the contact objects is a bullet and the other one is not. If it meets these requirements it sets a flag for the bullet to be deleted, then right before the world.step() method i check for this flag and delete the bullet and draw an explosion animation.


Top
 Profile  
 
PostPosted: Wed May 02, 2012 7:45 pm 
Offline

Joined: Tue May 01, 2012 3:45 pm
Posts: 7
Thanks so much for the quick reply.

We have a ContactListener already implemented so I'm not sure if the contact filter would fix it. Are they the same thing?

Also I'm not entirely sure I explained the problem correctly. I want to remove forces from bullets entirely. A problem I am having is even if the bullet does not collide with the player (goes straight through) it ends up applying a force to it for no reason that I can explain. The bodies of players are dynamic and bullets are set to bullets. Any help :|? I'm stuck.


Top
 Profile  
 
PostPosted: Wed May 02, 2012 9:52 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
You can implement the PreSolve function of your contact listener to check if the collision is a bullet and SetEnabled(false) for the contact so that no collision response occurs.


Top
 Profile  
 
PostPosted: Sun May 06, 2012 6:47 am 
Offline

Joined: Tue May 01, 2012 3:45 pm
Posts: 7
:D thank you thank you. Ended up solving it because of you guys.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: psbot [Picsearch] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group