• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How would I make a sword work in a platforming game?

D

debleb

Guest
I'm what you'd call a newbie programmer and I'm working on a platforming game about a rat with a sword, but how would I actually make the sword work?
 
Basically, you have a swing animation of some sort and during that animation, you create a hitbox object where the sword is slashing. There's not any major complicated programming to it. It's kind of like creating a still bullet. So you draw a rectangular sprite. Then create an object and give it the sprite. When you slash the sword, make the hitbox sprite appear in front of the player at the desired position. Delete the hitbox after the slash animation is over. Then make it so enemies react to touching the hitbox.

If your player moves while he/she slashes, you'll have to make the hitbox stay with the player by setting it to the players position and then adding your desired offset so that it's always in front of the player.

If you don't know what I mean, here's a tutorial from Shaun Spalding:
GameMaker Studio 2: Melee Attacks Tutorial

EDIT: Watching Shaun's video again, he uses a more advanced approach from what I said.
 
Last edited:
Top