How can i implement melee damage with paper2d?
I've spent several months trying to get my characters to do melee damage. I have all of my animations down. Monsters can do damage to me on touch, but the only way I've been able to get my characters to do damage is with projectiles. What I'm wanting is damage that follows the structure of a sword or mac. I've tried using timeline but I can't seem to understand how to properly use it with a time line, nor can I figure out how to attach collision boxes to just a few frames of a character with or without sockets. Could somebody please give me some more ideas to run with?
Super late, but better late than never ;)
There are many options you can use, most of which I probably do not know. However it's working fine for me the way I'm doing it, even if it's not the best.
I'm having trouble understanding what your issue is (how would you use timelines for this? that doesn't make sense to me. Only thing I used timelines for was sending the actor on the other end flying when struck). You could just use the already implemented per-frame collision built into paper2d. Just go into the flipbook and set the setting there.
Alternatively, you could do 3D box collisions like I am doing for my game since it is technically 3D.
Here's a .GIF of the game:
That barely took me any time to implement. What I did was make a macro for each attack, and use that whenever my character attacks. The combo system is a different thing, but if you'd like me to explain that too then comment on that and I'll do my best (not that hard).
So I made a function titled "Hitbox Adjuster" which when called resizes the collision box I setup around my player. This function is then called from within the macro to set the collision box's size depending on what attack is occurring.
Here's how simple it is:
In my case the Z isn't changing, which is why it'll always be 32.
Something I did was create an array with the actors that are currently overlapping that collision box. That way in my attack event/function I can loop through that array and apply the damage or whatnot to those actors. I then created an array of classes that my actor can hit when he slashes, and then I check if the overlapping actor belongs to any of those classes before adding them. And make sure to check that the object isn't there already, as it might be added to the array twice and when the loop occurs it could trigger the events twice for that actor.
Here's what it looks like:
I also created my own macro to detect when an animation has reached it's end (and a few other options) by having it compare the current flipbook frame to the flipbook frame length every .01 seconds.
Then, I create a few variables titled "IsAttacking", "CanAttack", "IsAnimationPlaying", etc. So here's how it would work in my case (dumbed down, but you'll get the basis):
Key Pressed -> Turn Animation Looping Off -> Wait for Animation End -> Set "IsAttacking" To On -> Set "IsAnimationPlaying" To On -> Update Animation (animation state) -> Attack Stuff.
I don't know if I was clear enough, so let me know if I can help with anything else.
Follow this question
Once you sign in you will be able to subscribe for any updates here