2D sidescroller combat, how do I start?

I want my player to have two methods of attack, a melee sword attack, but also a jumping attack (think mario). The melee sword attack I have a working script for, but I’m unsure how to start the jumping attack.

I want the player to be damaged if they walk sideways into the enemy, but if they jump and land on the enemy’s head, the enemy dies. Should I create a trigger zone on top of the enemy’s head to trigger the ReceiveDamage() script? Or should I programatically check if the player’s transform is right above the enemy’s?

I’m working in C#, but pseudocode is all I really need! Thanks ahead of time.

In the original Mario series (where you referred to, and that’s basically the core idea for what you have). It’s actually made that in the following way:

While the Player is moving downwards (e.g. after a jump),

Check if the Player if the playercollides with an enemy,

If so > Kill enemy

I hope that answers the question. :slight_smile:

EDIT: That only works if all the enemies do not fall faster than the player (which actually shouldn’t be the case normally, but you might play around with gravity here and then, so keep that in mind.)

i would prob stick with the 1 collider on the enmey and on the OnCollide check your position relative to the colided object. you can just make sure your y from the base of the object is higher then the y of the colliders top position. keep in mind this mean u can kill the enemey going at him in a 45 angle from the side

Given that you are using a CharacterController and that your enemies have a collider, you can use the CharacterController.collisionFlags to detect what part of the character collided. The ‘collisionFlags’ can be queried from the controller. They are also returned by the Move() function. They provide you information about what side(s) of the controller were hit on the last move. Note they will also report a collision with the ground and other objects, so you will need to do some Raycasting() or some other detection method to verify what was hit.