Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have an issue that I'm laughing at myself about, because it really seems like it should be something that I should be able to figure out pretty quickly.

I am designing a 2D action platformer; I have a playable character, and a dummy 'punching bag' character for testing purposes that I've created. I've just gotten enough of both of them done that I can start prototyping and testing them in runtime.

Then I realized- neither of them have references of each other (intentionally so), so how do I check for hitboxes stored within my playable character from my dummy character?

Long story short, how do I make my dummy know when he's been punched by my hero?

share|improve this question
I won't write a full answer, because really "it depends". However I think this answer might give you some inspiration. – Andrew Russell Jun 20 '12 at 4:42
"it depends" could be true of almost every situation in programming. Regardless, thanks for the link! – TheBroodian Jun 20 '12 at 4:45
up vote 2 down vote accepted

You don't need them to have references to each other.

Have a central hitbox system for your stage that does the work for them

Your hitbox system must have a list of all the hitboxes relevant to it - you'd generally have one hitbox system per world. How it finds out about its hitboxes is up to you, but the approach I take is (skipping all the detail) that every hitbox knows about the stage it's on, so it registers itself by calling: this.Stage.HitboxSystem.Add(this)

Once per update, this hitbox system goes through all the hitboxes known to it and lets them know if they're colliding with any other hitboxes (giving them whatever information is necessary, e.g. a reference to the other hitbox).

Next time your playable character or your "punching bag" need to know if they're touching anything, they've already been informed by the hitbox system and don't need to go check for themselves first.

share|improve this answer
Thank you for your input, this makes a lot of sense to me. I'll try it! – TheBroodian Jun 20 '12 at 21:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.