Add an Impulse in the right direction...( Side scroller game)

Hi guys i have a little problem, i made this simple movement script, If Pg Damage Boolean is false you can move, If Pg Damage Boolean is true you receive an impulse that push you back( X - 25000), so if you arrive from the left side everything its ok, you overlap the Enemy pawn and the boolean became true, but if you arrive from the right side you will be pushed in the wrong size How i can fix that issue ? I want that if you arrive from the right side you will be pushed in X 25.000. There is an “Enemy” in the middle that follow the player. Thank you.

225949-damagebug.png

Hi,

The Add Impulse node applies the impulse vector in the World coordinate system. I believe what you’re trying to do is to apply an impulse in the opposite direction your character is facing. If that is so, then all you need is to first find which direction your character is facing in the World space, and then multiply that unit direction vector with a negative impulse value. Here’s the blueprint setup you need:

Hope this helps :slight_smile:

Thank you I try tonight :smiley:

Cool it Work !!! I have only an answer, there is a way to constrain the impulse in the YZ Axis ?

You can break the Return Value of Get Forward Vector and just use the X value. In the case of a 2D game, this will most likely have no effect as Y and Z are already 0. However, in the case of a 3D game, you will at least need Y direction to apply the impulse in the right direction your character is facing.