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()
	

2Dシューティング

バレットはArea2D。プレーヤーと同じようにスプライトとコリジョンを設定

プレーヤーシーンに追加してバレットの大きさをチェック

バレットを削除して発射位置用のMarker2Dを設置

バレットのコリジョンをEnemyに当たるように設定。TopLevelをオンにするとプレーヤーの動きに左右されない

バレットのスクリプト
プレーヤーとの距離を指定しないとどこまでも直進するが、3秒後に消す

extends Area2D

# 移動スピード
const move_speed = 300.0
# プレーヤーからの距離
const bullet_range = 500.0

var direction = -1

func _ready() -> void:
	await get_tree().create_timer(3).timeout
	queue_free()

func _physics_process(delta: float) -> void:
	position.y += direction * move_speed * delta
	
	# プレーヤーから指定距離離れたら消す
	var player = get_tree().get_first_node_in_group("player")
	var distance = global_position.distance_to(player.global_position)
	if distance > bullet_range:
		queue_free()

2Dシューティング

extends CharacterBody2D

# 移動スピード
const move_speed = 100.0
# 傾き
var turnTilt = 4

var direction: Vector2

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

func _physics_process(delta: float) -> void:
	direction.x = Input.get_axis("move_left", "move_right")
	direction.y = Input.get_axis("move_up", "move_down")
	
	if direction.x:
		velocity = direction.normalized() * move_speed
		if direction.x < 0:
			rotation = -1 * turnTilt * delta
		elif direction.x > 0:
			rotation = 1 * turnTilt * delta
	elif direction.y:
		velocity = direction.normalized() * move_speed
		rotation = 0 * turnTilt * delta
	else :
		velocity = Vector2.ZERO

	position += velocity * delta

	# 画面の外に行かないように	
	var viewRect = get_viewport_rect()
	var viewOffset = Vector2(50, 50)
	position = position.clamp(viewOffset, viewRect.size - viewOffset)

	move_and_slide()

2Dシューティング

メインシーンにTaileMapLayerを追加。インスペクターで「新規Tileset」を選ぶ。今回のタイルは16×16なのでサイズはこのまま。下のエリアにTilesetをドラッグする。確認画面は「はい」

背景のタイルマップは飛行機に合わせて縦スクロールさせるのでParallaxBackground、ParallaxLayerの子に配置

ParallaxLayerのMirroringを720にして画面の縦サイズに合わせる

ParallaxBackgroundにスクリプトを追加。50の部分は縦スクロールのスピード

シーンを再生すると縦スクロールしていく

2Dシューティング

Godot 4.4.1
アセット:https://www.kenney.nl/assets/pixel-shmup

初期設定

■画面サイズ

■CollisionのLayer名を追加

■キー操作を追加

プレーヤーを作る

CharacterBody2Dを親としてSprite2DとCollisionShape2Dを追加

Sprite2DのTextureにタイルセットをドラッグするとタイルが表示される

Regionをチェックして「領域編集」で必要な部分を切り出す

四角のCollisionを配置する

画像がボヤけていると思うのでプロジェクト設定を変更する

PlayerのCollisionを設定する。
Layerは1のPlayerで衝突判定(Mask)は2のEnemyと4のEnemyBullet

メイン画面に配置

Playerシーンをメイン画面にドラッグして配置。青線の画面サイズに対してPlayerが小さいのでサイズを調整する

TransformのScaleを3.5倍

良さそうなサイズ

プログラミング

制作する人によって違うのが面白い。
どのようなゲームに実装するのかによって変わってくるんだろうと思う。

Github
https://github.com/morino5555/GodotExample/tree/main/hotbar


参考
https://www.youtube.com/watch?v=VqsMOanbbcc


参考
https://www.youtube.com/watch?v=PfhmtIJDiVA

プログラミング

Github
https://github.com/morino5555/GodotExample/tree/main/3d-sokoban

アセット
https://sona-sar.itch.io/voxel-animals-items-pack-free-assets

参考
https://kidscancode.org/godot_recipes/3.x/2d/grid_movement/index.html
https://www.youtube.com/watch?v=HmnwNadwHWI

グリッドサイズの移動は参考サイトの2Dと同じくグリッドサイズ分を移動させ、Raycast3Dで移動位置に障害物があるかチェックして無ければ移動する

ボックスも押されたらRaycast3Dで移動先をチェックして無ければ移動する

ゴールはArea3Dでボックスが来たらOKとする

メニューはControlで作成