How do I push enemies back when hit?

0 favourites
  • 3 posts
From the Asset Store
Helping streamers give their viewers more excitement.
  • Hello! I am making a top-down combat game, (very early stages), and I was wondering how I could push back the enemies when I hit them. I have when you left click it spawns a swing animation, and if it hits a zombie it damages it and stops it from following you. What I want it to do is push back away from the direction i'm hitting it, so combat can be a bit more smoother. Tell me if I missed anything, thanks!

    Here is the link to the game so far, please don't judge the art, it's not final and I made it in like 5 minutes. :P

    construct.net/en/free-online-games/combat-testing-help-17050/f82cc441-54c7-41d1-95b5-99c8625ebddf

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You need to Vector X and Vector Y in an angle from the player to the enemy. Something like this:

    Player on collision with Enemy:
    local variable a
     Set a to angle(Player.x, Player.y, Enemy.x, Enemy.y)
     Enemy set Vector X to cos(a)*100
     Enemy set Vector Y to sin(a)*100
    

    100 here is the force of the knockback.

  • You need to Vector X and Vector Y in an angle from the player to the enemy. Something like this:

    > Player on collision with Enemy:
    local variable a
    Set a to angle(Player.x, Player.y, Enemy.x, Enemy.y)
    Enemy set Vector X to cos(a)*100
    Enemy set Vector Y to sin(a)*100
    

    100 here is the force of the knockback.

    Unfortunately, I couldn't get this to work. But I was able to figure out a way that works okay for what i'm going for. I just set the angle towards either the player or the slash, depending on what hit it, and moving it at an angle -180 degrees. I may not be the best but I was able to figure it out. Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)