[05]エネミー(敵)を追加

2Dシューティング

プレイヤーと同じくCharacterBody2Dでエネミーを追加
Collision、Marker、Timerを追加してLayerを指定

シーンに追加してサイズを調整。2.5倍

VisibleOnScreenNotifier2Dを追加。画面の外に出た時に消去するのに必要

スクリプトはプレイヤーをベースに下への移動と画面外で消去
VisibleOnScreenNotifier2Dのノードで「screen_exited」を設定する

extends CharacterBody2D

# 移動スピード
const move_speed = 100.0

var direction: Vector2

func _ready() -> void:
	add_to_group("enemies")

func _physics_process(delta: float) -> void:
	direction.y = 1
	velocity = direction.normalized() * move_speed
	position += velocity * delta

	move_and_slide()

func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
	print("outside")
	queue_free()