Godot2D・剛体はマウスの動きにつき従う

# Godot 4.1
extends RigidBody2D

# ノード
var node0

# データ
var target

# 初期化
func _ready():
    node0 = get_node(".") # 自分のノードを取る

# フレーム実行
func _process(delta):
    follow_mouse()

# インプット事件
func _input(event):
    if InputEventMouseMotion: # マウス移動
        target = get_global_mouse_position() # マウスのグローバル座標を取る

# マウスにつき従う
func follow_mouse():
    node0.position = target # ノード座標とマウス座標を同期する