Beginner Combat


So this time I wanted to make the enemies and the knight interact in some way. Obivously they can't be best buddies,so they have to fight. That's what enemies do.

Attacks

I will start with two attacks from the knight. Later on I want him to have dedicated attacks for more directions.

Neutral Attack

A wide swing, a bit slower, but it's supposed to be the attack with more damage.

I reused this attack for the jump attack. (I want a new one later on)

Walk Attack

A  stab with more range but less damage.

All of these attacks will get a hitbox effect. It looks nice and indicates where exactly your hitbox is. It also makes the range of the attack adjustable and not limited to the sprite. (You can see these in the next gifs)


Actual Combat

Now these animations need to have an actual impact. The enemies need some kind of reaction (I mean they are getting a giant pencil into their face, ouch) and preferably a death animation. I will show the back end of how I implemented this interaction at the bottom of this log.

Let's show some gameplay instead of only animations.


Here you can see the hitbox indicators I spoke about. It is almost like shockwave of ink, extending the range of the attack as much as you want.

The slime also has some knockback to make the attack have an impact. Also some hit animation and a death animation.


Pretty much the same for the fly. The jump attack is still WIP.


Implementation

Hitbox / Hurtbox system

This system is used in all the good ol' fighting games we love. A hitbox is a shape where the actual attack happens.If you are attacking and this hitbox collides with a hurtbox, the entity takes damage.

First I seperated the interaction between hitboxes and hurtboxes in the PhysicsManager.


This way we don't have unwanted physics interactions.

For some code it's pretty straight forward.


Look for an overlapping hurtbox collider, get the script and call the function that should execute the damage.

I added one feature, a lingering hitbox. Right now it's is only one frame of damage. My stab for example has traveltime and it wouldn't feel right if it's only one frame.


The damage function needs some kind of callback, a bool return in my example, that tells the hitbox if it hit anything.

This way you can activate the hitbox to your liking, with animations for example.

For the hurtbox I went with a simple implemenation.


If the attacked entity has a health component, it just takes damage. I included the direction for some knockback animations.

One final thing that might be noteworthy. I activate the hitboxes via animation events. Easily adjustable and frame perfect.


I will probably add features to this system when I need additions in the future.

Leave a comment

Log in with itch.io to leave a comment.