Godot Version
extends Area2D
class_name EnemyBullet
@export var speed = 5
@export var bullet : PackedScene
signal toggle_enemy_hit(is_hit : bool)
var enemy_hit : bool = false:
get:
return enemy_hit
set(value):
enemy_hit=value
emit_signal("toggle_enemy_hit", enemy_hit)
var direction := Vector2.ZERO
signal bullet_hit
Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _physics_process(_Delta):
if direction != Vector2.ZERO:
var velocity = direction * speed
global_position += velocity
func set_direction(direction: Vector2):
self.direction = direction
func _on_body_entered(body):
print(“hit player”)
if body.is_in_group(“player”):
bullet_hit.emit(body)
body.hide()
queue_free()
#body.queue_free()
Question
trying to set up enemy bullet and after shooting one bullet game crashes and gives the cannot call method 'add_child" on a null value.