How to get which direction an object was hit from?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jax1221

I have a simple project, a KinematicBody2D player, some KinematicBody2D enemies, and a gun that shoots KinematicBody2D bullets. When the enemy runs out of HP, if falls in the opposite direction that the sprite is facing. This is fine, unless the player shoots the enemy in the back and kills it, when that happens the enemy falls over in towards the player. So what I’m asking is: is there a way for the enemy to get the direction it was hit from, and fall in that direction when it was killed? Any answers are appreciated, and thank you for reading this far.

:bust_in_silhouette: Reply From: kidscancode

Presumably you’re detecting the collision between the bullet and the enemy. When you do that, one of the pieces of information contained in the KinematicCollision2D object is the collision normal. You can use this to tell from which direction the collision occurred.