メインコンテンツへスキップ

Godot - 剛体をマウスの動きにつき従う

·65 文字
icysamon
著者
icysamon
電子工作・クリエイター
# Godot 4.1

extends RigidBody2D

var node0

var target


func _process(delta):
    follow_mouse()


func _input(event):
    if InputEventMouseMotion:
        target = get_global_mouse_position() # マウスのグローバル座標を取る


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