Godot Version
4.2.2
Question
I have this code that instantiates a bullet when I fire it
func fire():
var bullet_instance = bullet.instantiate()
bullet_instance.position = get_global_position()
bullet_instance.rotation_degrees = rotation_degrees
bullet_instance.apply_impulse(Vector2(BULLET_SPEED, 0).rotated(bullet_rotation), Vector2())
get_tree().get_root().call_deferred("add_child", bullet_instance)
and this code in the bullet scene that causes the bullet to delete when it collides with any object.
extends RigidBody2D
func _on_body_entered(body):
queue_free()
if body.is_in_group("Players"):
body.damage_taken()
The bullet is colliding with the objects, but it isn’t getting deleted. I’ve checked that the collision is masking the object it’s trying to collide with (the bullet is on layer 4 and the test object is on layer 3, the bullet is masking layer 3 and the test object is masking layer 4), but the bullet isn’t deleting. What could cause this? I’ve made a previous game that has used this exact code and worked perfectly.