playMaker

Author Topic: 2D player knockback (when hit by an enemy) [SOLVED]  (Read 1577 times)

maxrostov

  • Playmaker Newbie
  • *
  • Posts: 18
2D player knockback (when hit by an enemy) [SOLVED]
« on: November 10, 2020, 03:40:01 PM »
Hi.
I've created a state in which the player enters if hit by an enemy.

The state is suppose to make the enemy push the player away from himself.

Currently the player does get pushed back when the enemy attacks from the left.
But when the enemy attacks from the right, the player gets pushed INTO the enemy instead.

I guess i'm using the "Vector3 Invert" in a wrong way.

Does anyone know why that is?

Thank you in advance!  :)
« Last Edit: November 12, 2020, 02:40:34 PM by maxrostov »

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: 2D player knockback (when hit by an enemy)
« Reply #1 on: November 10, 2020, 06:32:58 PM »
Direction * -1 will flip the direction.

maxrostov

  • Playmaker Newbie
  • *
  • Posts: 18
Re: 2D player knockback (when hit by an enemy)
« Reply #2 on: November 11, 2020, 02:12:06 AM »
Thanks for replying!

I've tried to set the multiply on a negative number, but that only reversed the problem (player only gets pushed when attacked from right, but player gets drawn into the enemy when attacked from left).

I need the player to get pushed to the opposite direction from where the attack comes from. Isn't that was Vector3 Invert should do in this case?


PS: When I remove Vector3 Invert, nothing changes. So it's obviously not working. Am I using it wrong, or is that action in Playmaker broken?
« Last Edit: November 11, 2020, 02:16:08 AM by maxrostov »

maxrostov

  • Playmaker Newbie
  • *
  • Posts: 18
Re: 2D player knockback (when hit by an enemy)
« Reply #3 on: November 11, 2020, 02:08:17 PM »
Here's a video of the issue (players is only bouncing away from the enemy from one side): https://share.vidyard.com/watch/X2iA7rUt3h5dBiemDnnkkX?

Does anyone know what Action in the FSM that adds force to the opposite direction?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: 2D player knockback (when hit by an enemy)
« Reply #4 on: November 12, 2020, 05:18:30 AM »
Hi.
You need to get the side where the player is.
if 2d : get pos X from player and enemy then do float compare.

then depending on which side, do negative or positive multiply.

maxrostov

  • Playmaker Newbie
  • *
  • Posts: 18
Re: 2D player knockback (when hit by an enemy)
« Reply #5 on: November 12, 2020, 02:39:29 PM »
Hi.
You need to get the side where the player is.
if 2d : get pos X from player and enemy then do float compare.

then depending on which side, do negative or positive multiply.

It worked like a charm - thank you!!

- State1: First I did Collision 2D event. IF collider tag is Enemy, then next state.
- State2: "Get position" of player, and collider. Then float compare of those two variables.
 
(Instead of get the enemy pos, I used get the collider position - because I want this effect to take place when hit by all enemies)

The next two states are either pos or neg multiply.
« Last Edit: November 13, 2020, 11:34:03 AM by maxrostov »