Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialChris Tapia
1,684 PointsMultiple hits
Hey i finished this video and got the same exact results except for one issue. Some enemies would take multiple hits to kill, as opposed to Amit's results where the enemies have the standard one hit kill thing. It is randomly generated, so some enemiees take one hit while others might take 7. What do I do? Please help!!
2 Answers
Nick Janes
5,487 PointsHello, I am also having this problem. I don't think its that they take more hits though, I think its just that the hits aren't being registered.
Chris Tapia
1,684 Pointsthanks nick!!!
Nick Janes
5,487 PointsNick Janes
5,487 PointsI've done it! I've found the solution. In the didBeginContact method, change this section of code(The first if statement checking collision):
if ( contact.bodyA.categoryBitMask == CollisionCategoryEnemy && contact.bodyB.categoryBitMask == CollisionCategoryProjectile) {
to this(Changing the contact.bodyA and contact.bodyB to firstBody and secondBody):
if ( firstBody.categoryBitMask == CollisionCategoryEnemy && secondBody.categoryBitMask == CollisionCategoryProjectile) {
My hypothesis to why is because the didBeginContact is constantly being called upon collision because of the other nodes colliding, and due to threading, is changing around the first and second body variables before it can evaluate them.