Hello all,
I am new to Chipmunk but am finding it to be an excellent engine.
I have a question regarding collision detection that I'm hoping someone can chime in on. I've posted the same question to the cocos2d-iphone forum since I'm using Chipmunk and cocos2d on that platform.
What I'm trying to do is detect two different types of collision on a single body. The first one (which is larger than the body) would occur when one body gets within a certain proximity of another (e.g. two enemy units coming into range of each other). The second (which is the same size as the body) would occur when an actual bullet collision occurs on the body.
Does anyone have any ideas on how to implement this that could get me going in the right direction? I tried creating two shapes on a Chipmunk body but I only seem to see the larger shape receive the collision callback.
Thanks in advance for any help!
Collision Detection Question
-
- Posts: 2
- Joined: Sun Jan 04, 2009 5:17 pm
- Contact:
-
- Posts: 56
- Joined: Tue Sep 11, 2007 2:30 pm
- Contact:
Re: Collision Detection Question
The idea with two shapes sounds to me like it should work. Make sure you're returning 0 from the collision callback for the larger shape. Also, if your smaller shape is very small, and the bullet travels very fast, it could be that it jumps right over your body, since we don't have swept collisions.
That's all I could think of that could go wrong. If neither of these suggestions help, maybe you could post the code you use to set up the body and the two shapes?
That's all I could think of that could go wrong. If neither of these suggestions help, maybe you could post the code you use to set up the body and the two shapes?
-
- Posts: 2
- Joined: Sun Jan 04, 2009 5:17 pm
- Contact:
Re: Collision Detection Question
Thanks for the response, supertommy.
I modified things slightly and it seems to work: rather than make the larger shape enclose the smaller one, I put the larger shape in front of the object to act as a proximity detector. I then just differentiate which game object shape triggered the collision and act appropriately.
I modified things slightly and it seems to work: rather than make the larger shape enclose the smaller one, I put the larger shape in front of the object to act as a proximity detector. I then just differentiate which game object shape triggered the collision and act appropriately.
-
- Posts: 29
- Joined: Wed May 09, 2012 12:06 am
- Contact:
Re: Collision Detection Question
I had a similar need in my project and this worked fine for me as long as the larger shape was a sensor. I preferred to classify it as a sensor rather than return false from preSolve (as was suggested previously) because sensors are automatically excluded from cpSpaceNearestPointQueryNearest (docs don't mention this) and cpSpaceSegmentQueryFirst.
Who is online
Users browsing this forum: Heise IT-Markt [Crawler] and 9 guests