How to add knockback into a top down rpg?

Hello!

I have been trying to make a small top-down rpg, where when an enemy gets hit by the player’s sword, they get knockbacked, but I haven’t been able to get it to work. I have seen and been following the tutorials called “Game Mechanic Breakdown - Enemy KnockBack - Part 1 + 2”, and “Game Mechanic Breakdown - Alerted Enemy - Part 1 + 2”, as well as “How To Add Melee Beat’em Up Combat To Your Game - GDevelop”, but it hasn’t been working. Does anyone know what I can do? Any help is appreciated :slight_smile:

Also, if anyone knows a guide, either on here or on youtube, that shows how to make enemies respawn after you kill them, I’d also appreciate it a lot!!!

No need to pause animation if you change it below it

You are expected to provide angle yet you provided position
So in add force action in angle Hero.AngleToObject(Enemy)

Thank you for such a fast reply!

I did it, but unfortunately it didn’t work, am I doing something wrong? Do I need to maybe remove the Enemy constantly chasing the player?

Remove this
And here add
INVERTED animation of enemy = hurt

You can double click condition and there is toggle switch to invert it

Thank you but unfortunately this didn’t work either, but it’s okay, I’m just testing stuff with programming so thank you either way!

I’ve found permanent forces linked to animations can problematic. I tend to use an instant force linked to a variable ‘hurt’ and use a variable ‘hurt angle’ so that it slows down as ‘hurt’ decreases. We’ve all got our own methods and I can see the advantages of the method above but you do have to make sure you stop that force. You can also use an object timer to control the length of the knock back force. Experiment and see what works for you.

The method “hurt” variable and “hurt angle” variable seems very interesting and like it could work. If you don’t mind, could you share an image of how you do it? I tried it but I didn’t know how so it didn’t work.

sorry for a slow response. Basically this sort of thing.
Screenshot 2026-08-20 202010
i usually have a variable ‘hurt’ and ‘hurtangle’ and at the point of collision set the hurtangle for object A to be the angle from object B to object A and then set ‘hurt’ to however much you want it to move and stay hurt for. Sometimes like above i keep the recoil or knockback separate from how much it is hurt.
you can use the ‘recoil’ variable and times it by something or use any maths expression to achieve what you’re after. I looked back at all the knockback threads on the forum and there’s loads. There’s quite a few different ways by cleverer devs than me and so its worth looking at those as well!