Jump to content
  • Advertisement
Sign in to follow this  
Sean_Seanston

Simplest practical way of doing melee weapons?

This topic is 2636 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm implementing melee weapons in a 2D top down shooter I'm making. So far, I have projectile weapons that fire projectiles and enemies that can collide with projectiles etc. and the rough layout of the logic is something like this:

GameWorld class updates Projectiles etc.
Enemy/Player/etc. objects have weapons which may spawn Projectiles as part of the GameWorld calling the Enemy/Player's update function.
GameWorld then calls collision checking functions which check Enemy against Player, Projectile against Enemy etc. and take appropriate action.
etc.

Now, my melee weapon class is based on the projectile weapon class and I'm about to change the projectile spawning to whatever I need to do for melee weapons. BUT... I'm wondering a few little questions as to how to approach this.

Melee weapons are going to use a collision circle to determine if an Enemy has been hit. So when the fire button is pressed, I have to set that checking into motion somehow.
I thought first about having the check occur then and there but does that seem like a bad idea? The melee weapon would have to get involved with stuff it probably shouldn't be and it seems to potentially put melee weapon collisions out of order with other collisions, which occur within GameWorld's update function.

So, I'm now moreso thinking:
When fire is pressed, the melee weapon adds a collision circle to some list in GameWorld (like Projectiles etc.) and nothing else. Then GameWorld checks through the list of circles and deals with them more or less as it would any other collision. The circle then also needs to have some kind of timer to destroy it after a certain amount of time if nothing collides with it.

Is that really the most practical way of going about this? It just seems kind of... "dangerous" and messy to check for collisions right after the attack command has gone through but somehow it seems more elaborate than I would've thought possible but then... of course everything in game development turns out more complicated in reality than you'd ever have thought so maybe I'm just overthinking :rolleyes:.
Does anyone know out of curiosity, roughly how games like Zelda used to deal with simple melee combat? Or if anyone has implemented something similar in a 2D game, I'd be interesting in hearing how it was done.

Share this post


Link to post
Share on other sites
Advertisement
[color=#1C2837][size=2]Now, my melee weapon class is based on the projectile weapon class...[/quote]You're on the right track by treating melee and ranged weapons the same way. The reason you want to do this is so you handle them the same way. Spawn a melee weapon the same way you do a projectile. In essence, the "blade" of the weapon is the projectile. Just make sure you can only spawn one at a time and make the projectile responsible for knowing how to move and when to die.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!