0 votes

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.

in Engine by (17 points)

1 Answer

0 votes
Best answer

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.

by (20,899 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.