using Godot; public partial class Bullet : Area2D { [Export] public float Speed { get; set; } = 600.0f; public Vector2 Direction { get; set; } = Vector2.Zero; public override void _Ready() { // Subscribe to the built-in BodyEntered event when the bullet is spawned BodyEntered += OnBodyEntered; } public override void _PhysicsProcess(double delta) { Position += Direction * Speed * (float)delta; } // This method is triggered automatically when the bullet hits a physics body private void OnBodyEntered(Node2D body) { // QueueFree safely deletes this node and all its children at the end of the current frame QueueFree(); } }