Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm starting development on a 2D overhead RPG game, and am wondering what the best approach for handling weapon collision and dealing damage to enemies is.

I'm currently using a basic Entity/Component structure for my game objects. I have a CharacterEntity, that has an EquipableEntity data member. The CharacterEntity has a component that listens for input. When a command to attack is received, the CharacterEntity is set into an attack mode where an attacking component gets the equipped entity and moves it in the attacking motion. Any collisions detected with the moving equipped entity in the world are then registered as successful attacks. Once the attacking component determines the attack is finished, the CharacterEntity leaves attack mode and returns to it's normal state.

Weapon collision is a basic LWJGL Rectangle that tests the .interesects() method, checking against all enemy rectangles. Currently it's just a stabbing motion (it moves out to x length, then returns).

The reason I did it this way was:

1) I wanted enemies to receive and respond damage as the sword crosses their path, instead of just saying "attack occurred in this general area" and having all enemies update at once. In the stabbing case, an enemy at the full length of the sword wouldn't take damage until the actual sword entity crosses it's path.
2) The weapons define their own appearance and boundary on the screen, making it easier to animate and sync with the game.

I'm entirely new to game development (if you haven't figured that out already). Is this the appropriate way to achieve the result I'm looking for, or complete overkill? How does a game like Terraria (where weapons move in a sweeping motion) or the Zelda series handle attacking and determining what enemies to hit and when? Am I on the right path or totally off?

Any advice or suggestions would be greatly appreciated.

share|improve this question

2 Answers 2

Does the game resolve collisions the way you want it to? If so, I don't think you're off track at all. There is no right or wrong answer here. These kinds of logic decisions are totally open and have to be made based on how you envision your game behaving. Game developers make these decisions on a daily basis.

What I would say is this: Terraria is platform game, and a very retro one at that. What this means is you can typically get away with a more simplistic approach to collision detection, eg. the approach you've implemented. I'm also writing a top down action game with melee combat. My approach was to use Box2D for the collision detection so that sword swings etc. are accurate, realistic, and very fast to process. Realistic means attacks will impart linear and angular impulse to objects. So when you hit something, it can spin and be knocked back. It's a simple step to add breakable objects, too, i.e. if (force > object.strength) object.break();

If you are planning on making future games, you can't go wrong learning Box2D, it's available for every major language. However if you are just testing the waters of game development, so to speak, then keep it simple: stick with your present solution for now.

share|improve this answer
    
I really hate the "KISS" acronym... –  Jonathan Connell Aug 4 '11 at 12:09
    
What's wrong with Knights In Satan's Service? Inaccurate ... but .. still ...yeesh. :) –  Stephen Aug 4 '11 at 12:32
    
Wow there's a lot of love here eh guys? :) –  Nick Wiggill Aug 4 '11 at 12:35
    
It's nothing personal, just that I knew an incompetent producer that used acronyms all the time to try and sound clever. KISS was her favourite. –  Jonathan Connell Aug 4 '11 at 14:14

The answer to your question depends on the features and style of your game. For example your approach may be useful if it will be possible to throw the sword(dagger) or damage regions of enemies bodies (like in Fallout).

share|improve this answer
2  
answer is "it depends" lol –  GameDev-er Apr 16 '13 at 17:50

Your Answer

 
discard

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.