Multiple actors registering touch

SinequanonSinequanon Member Posts: 35
edited November -1 in Working with GS (Mac)
I haven't seen a tutorial on this so far, but maybe someone can point me to one.

Say I'm making a whack a mole game. If my player misses, I want to play an animation and sound to acknowledge they missed. If they hit a mole, then I want the mole to react and for there to be a different animation played on it, and a different sound.

So far, my moles will react properly, but when I drop in the behavior onto the background that when it receives a touch, to play the sound, it pretty much always plays, regardless of whether I hit a mole or hit just the background.

Essentially, I want to know a smooth way of ensuring that only one enemy is hit, or the background is hit. It'll never be the case that both should register a touch in this game. Any help is greatly appreciated. I'm doing a big presentation on GS in my company tomorrow and getting this game working perfectly would go a long, long way.

Comments

  • hotMagichotMagic Member, PRO Posts: 266
    I've tackled something similar in my game.
    Since you can't have two things being touched at once, put a game level variable that is IsMoleHit.

    Make the BG object only do the sound if it's hit AND IsMoleHit=0.

    Every time a mole is hit, make the IsMoleHit 1, and every time a mole touch is released, turn it to 0.

    I don't have my mac right here or I'd show you the code.

    if there is a timing issue with that (since they are both assigned at the same time), the dirty shortcut is to delay the fail sound by like .5

    The other way that comes to mind is to only play sounds from the BG. Because if the moles are behaving fine, then you can avoid ever having sounds play at the same time by letting the BG be sound manager.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Well actually touch will register for everything underneath it. if you have to dragging actors that get on top of each other they will both lock to the same touch and without some rules you will not get them apart.

    I think hotmagic might be on the right track as long as the background is only affected by the mole touched attribute and never controls that attribute. Utopiangames made something work real nice in Bumps and I think he did a tutorial on how to do it but I don't remember you should prob try contacting him about it.
  • SinequanonSinequanon Member Posts: 35
    hotMagic: That's kind of what I have going on right now; the enemies have a rule that when they receive a touch, and game.hit = 0 (signifying that nothing else has registered a hit), then they do their thing. I also have a timer running in the background every 0.1 seconds that resets that game.hit attribute to 0, because it was getting stuck to 1 (it showed in my debugging) for some reason. Despite this, if two actors are stacked on top of each other (two moles, in this instance), they will both register a hit. It's kind of frustrating but not that big of a deal ultimately, for moles. For the background, it is, though.
Sign In or Register to comment.