Hit emeny and have them move backwards after impact

Hello,

Have hit another issue with the enemies in my latest project, which is a top-down maze/Gauntlet type game.

So, I have a hero actor who is pursued by enemies. These enemies have limited AI that cause them to home in on the actor. Their rotation angle is constrained so they're always facing the hero actor, and they move in a direct path towards him constantly.

The hero can strike them with a sword and when he does that, I want the enemy to be pushed backwards away from the hero for a second or so. I thought this would simple and that I could trigger a situation when the enemy is 'hit' that he moves in the direction of his current rotation+180 for a second. I figured this would keep him facing my hero but shove him back along his exact reverse path. I'm having real difficulty with this. Firstly, I'm not sure if simply adding 180 to the angle will produce the effect I want, I'm assuming there is a proper mathematical way to figure this angle out? And secondly, I can't seem to get the movement to work. I've tried move and accelerate commands but I seem to produce something that has no effect whatsoever or permanently makes my enemy go shooting off in all manner of directions infinitely! I thought my movement controls were to blame for this, see my previous thread for the movement issues I had there;

forums.gamesalad.com/discussion/86026/my-enemies-cant-take-corners-funny-but-very-annoying#latest

But I've set it up so that when the emeny is 'hit' all his existing movement and acceleration commands should be suspended. I'm a bit stuck!

Best Answer

  • SocksSocks London, UK.Posts: 12,822
    Accepted Answer

    Throw the speed value of the enemy's movement into reverse for a moment.

    So if the enemy is moving towards your hero as a speed of 100, change it to -100.

Answers

  • mysticjimmysticjim Member Posts: 30

    Hot damn, that did it! thanks!

  • SocksSocks London, UK.Member Posts: 12,822

    @mysticjim said:
    Hot damn, that did it! thanks!

    To make it a little more slick, try replacing the enemy's speed with an attribute (let's call it NME_Speed), when you need it to move backwards simply interpolate NME_Speed from its current speed to the negative value (e.g. 100 to -100), so the transition from moving forward to retreating is less abrupt.

Sign In or Register to comment.