#2D character controller and knockback

1 messages · Page 1 of 1 (latest)

broken falcon
#

I'm making 2D top down character controller. Right now it looks something like this

direction = get input direction
velocity = (direction * speed)
if not direction.x:
  decelerate x
if not direction.y:
  decelerate y

Now what if I want to receive knockback from getting hit by an enemy? If I add the knockback vector to velocity, it will just be overwritten the next frame and reset back to the movement velocity. How do I make a character controller that allows for knockback?

vivid harbor
#

You could add a knockback_velocity which gets set by enemies, then each frame that is re-added to your velocity. Alternatively you could make a taking_knockback boolean, and make it so while you're taking knockback it ignores input direction.

broken falcon
#

Ok. I was also thinking this separate external_velocity vector that gets added to the velocity from the player input, but I've never heard of this before so I asked incase I was missing some obvious solution.

worthy oyster
#

Maybe use one of the apply_ like force , impulse, rotation

dreamy igloo
#

you could have 4 damage thingy detectors and if it hits the top one the player goes down if from left it goes right if from right left