0

I am building a SpriteKit game in which two nodes, one moving and one stationary make contact. This contact increments a variable holding the score.

Everything is working, but the two nodes that make contact will often record more than one contact, resulting in several increments when it should only be returning one.

The strangest part about it is that I have the stationary node CHANGES PLACES upon contact, so why would it detect multiple collisions for just one hit if it doesn't even stay stationary? I've even tried just removing it upon contact to get it to increment only once upon a hit, and even that still results in multiple collisions.

As of right now I am just using:

if firstBody.categoryBitMask == HeroCategory && secondBody.categoryBitMask == BellCategory {
    score1++
    scoreText.text = "\(score1)"
}

But have tried many other situations including using

didEndContact

and changing the

restitution

Any help would be much appreciated.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
TerranceW
  • 302
  • 2
  • 12
  • wait you are moving the stationary node? Where and how? – MaxKargin Aug 11 '15 at 23:03
  • I am using a boolean that when true activates a conditional in the update method that contains a position property change for the node. The node just moves along the x-axis of the frame while retaining the same y-axis values. So the node is stationary on a physicsJoint until it makes contact with the node the user is controlling, at which point it changes position along the x. – TerranceW Aug 11 '15 at 23:09
  • @M321K Could it be possible that it's on the physics joint? – TerranceW Aug 11 '15 at 23:18
  • what happens to the non-stationary node post-contact? And the contact won't be from the physics joint – MaxKargin Aug 11 '15 at 23:29
  • The non-stationary node just falls back down the y-axis. What I meant by that was maybe the physics joint is causing the stationary node to swing around and possibly cause more collisions? @M321K – TerranceW Aug 11 '15 at 23:35
  • Well, I'm not totally sure whats going on. do you have the SKScene showing your physics nodes? – MaxKargin Aug 11 '15 at 23:38
  • The nodes are showing in the scene yes if that's what you're asking. Or were you asking for a screenshot? @M321K – TerranceW Aug 11 '15 at 23:49
  • I mean do you see the the actual physics nodes not the sprite nodes? that way you can tell if there is other contact going on – MaxKargin Aug 12 '15 at 00:17
  • I'm nearly certain that there is no other contact going on besides that of the two nodes previously mentioned. What I think is happening is the non-stationary node hits the stationary one in several places or continues to hit it, or something like that. I just want one contact registered. One node is a circle, and the other is a sort of strange oblong bell shape, I believe the non-stationary node (the one the user controls) is repeatedly hitting the bell shaped stationary node when it looks like it's only hitting it once. – TerranceW Aug 12 '15 at 00:35
  • Yeah so what you need to do in your viewController when you create the scene specify `skView.showsPhysics = YES` and then see if contact occurs multiple times – MaxKargin Aug 12 '15 at 00:47
  • Some possible solutions : http://stackoverflow.com/a/30855791/3402095, http://stackoverflow.com/questions/28526694/physics-detecting-collision-multiple-times, http://stackoverflow.com/a/23367987/3402095 – Whirlwind Aug 12 '15 at 01:32
  • @Whirlwind Thank you that stuff is great. I had considered using the timer way, but am not sure quite how to set up a timer like that. I am familiar with some of the timing mechanism but not quite sure how to run a timer like that. Thanks. – TerranceW Aug 12 '15 at 06:39

0 Answers0