Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | rasmushassenkam |
Hi, I am learning godot and I have some problems with collision detection.
I am doing a top down shooter, and I have a bullet which is an Area2d and an enemy which is a Kinematicbody2d, both have a CollisionShape2d attached. I have connected an on_body_entered to the bullet, in this I want to emit a signal and connect this to the enemy to let it know that it had been hit. My problem is that it seems like the enemy does not observe the signal. i’ve tried putting in a print in on_body_entered in the bullet, and that fires every time the enemy is hit, but I want to be able to detect this hit in the enemy. I’ve pasted in the code for the bullet and enemy below.
Bullet:
extends Area2D
var velocity = Vector2.ZERO
signal hit
func _physics_process(delta):
position += velocity * delta
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
func _on_Bullet_body_entered(body):
emit_signal("hit")
queue_free()
Enemy:
extends KinematicBody2D
func _on_Bullet_hit():
print("I'm hit")
I edited your post for code formatting. In future, please try and format your code samples (4 spaces before each line, or there’s a button in the editor).
kidscancode | 2020-05-20 18:48