Home Artists Posts Import Register

Content

So I've done my research (which largely these days involves some consultation and idea bouncing with other strong developers in r/GameMaker's discord) and finally decided on my approach for this video. It's been a toughy as there's lots of different approaches, but I don't want to be coming back and doing this video again in a year so I wanted the most comprehensive thing I could come up with.

I'm going to use a platformer just so that this is based around code most of you will recognize, and I'm going to split the video into two parts. Part 1 is going to talk about setting up "An attack". Auto-combos will follow in Part 2.

I've had to do some rare Art™ing for this one and was inspired by Kris' hot new combat sprite idle pose in Deltarune, so I based the idle on that and went from there, creating a run, idle and attack!

The way this is all planned to work is actually fairly elegant. The idea whenever I make a tutorial is to find the best balance of simplicity (a method that can fit in a video) and flexibility (viable extension and edge case coverage). The "Best method" is almost always out of the running and this is no exception. But the method we're using is actually pretty comprehensive in this case and could very easily support a whole game built around it.

1. A state machine governs the player and whether or not they're attacking (This is important for Auto-Combos later, mostly)

2. When pressing attack, we swap to the attack animation + state. We also create/clear a DS_LIST that tracks enemies that have been hit by the attack.

3. When playing the attack animation, each frame we swap out the player's sprite for a precise-per-frame hitbox sprite that is matched up to the attack animation. (Unfortunately, only precise hitboxes have a per-frame option in GameMaker currently.)

4. We check for collisions with this new sprite, using the collision list function.

5. We compare the IDs of anything we hit to a DS_LIST of previously hit enemies. This is to make sure we don't hit the same enemy twice with a single attack (over two frames for example). This means we can use multiple players, multiple enemies, various different combos and multi-hitting attacks with ease!

6. Anything we can hit, we add to the DS_LIST and process accordingly. We then swap back to our regular sprite before actually rendering! Smoke and mirrors complete.

I have a bit more Art™ing and coding to do today but then it's on to recording. The code etc will as always be available to $5 patrons when the video releases.

Files

Comments

Anonymous

really excited about this. I actually used your platformer series as a basis for my game and I am slowly converting my 3 characters to have their own unique combat, which one is a knight with a sword and the other two shoot projectiles (archer and a mage) so this will be a huge help that my knight can actually do melee combat and these methods sound great.

Anonymous

ok i am concerned though most likely will be answred later.. If our hit box is whats doing damage how does the player risk taking damage while attacking from enemies ?

shaunjs

You use a regular collision box most of the time, you only swap to an attack hitbox to check for any hits, then swap back (in the same code chunk). When it comes time to check for a collision between enemies/hazards you're back to your regular 'hurt'box