メモ

extends CharacterBody3D
@export var speed = 14.0
@export var rotation_speed = 4.0
var cam_spring_arm # Reference to your SpringArm node
func _ready():
    cam_spring_arm = get_node("SpringArm3D") # Or however you access it
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) # Optional: Capture mouse for FPS-like controls
func _physics_process(delta):
    # Movement
    var input_vector = Input.get_vector("move_left", "move_right", "move_backward", "move_forward")
    var velocity = Vector3.ZERO
    if input_vector != Vector2.ZERO:
        velocity = (transform.basis * Vector3(input_vector.x, 0, input_vector.y)).normalized() * speed
    
    #Rotation
    var aim_vector = Input.get_vector("aim_left", "aim_right", "aim_down", "aim_up")
    if aim_vector != Vector2.ZERO:
         rotation.y -= aim_vector.x * rotation_speed * delta
         cam_spring_arm.rotation.x -= aim_vector.y * rotation_speed * delta
         cam_spring_arm.rotation.x = clamp(cam_spring_arm.rotation.x, deg_to_rad(-75), deg_to_rad(75))
    velocity.y -= 9.81 * delta # Gravity
    # Apply movement
    move_and_slide()
func _input(event):
    if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed():
        Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
    elif event is InputEventKey and event.keycode == KEY_ESCAPE and event.is_pressed():
        Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

メモ

空の「Node3D」にグリッドマップ用のglbファイルをドラッグ

右クリック「ローカルにする」で変換

変換されたファイルをドラッグして元ファイルを削除


「StaticBody」とコリジョンメッシュを追加

メッシュとして保存してGridmapの右ペインにドラッグ

メモ

https://zenn.dev/syun77/articles/a3d3dcbf260b90


Area2D」「CharacterBody2D」「StaticBody2D」「RigidBody2D」の考え方

後から変更できるらしいが「使用例」参考になる


「kinematicbody2d」->「CharacterBody2D」?

Godot 4 で KinematicBody2D はどうなったの? : r/godot


フォルダの構成

root
+ assets (画像など)
  + images
  + fonts
  + tile
  + sound
+ scripts (gd スクリプト)
+ scenes (tscn シーン)

自分的にはこんな感じにしたい

root
+ assets (画像など)
+ src (tscn / gd)

こんな感じでも良いかな


カメラ追従

CanvasLayerはデフォルトでカメラのスクロールを無視する設定となっています。
カメラに追従させるにはインスペクタから「Follow Viewport > Enabled」を有効(オン)にします。

CanvasLayerの注意点