generated at
Godot: direction_to
Godot Engineで、ある地点から別の地点への向き(direction)を算出する Vector2 の便利関数
環境: Godot 4.0 stable
> Vector2 direction_to(to: Vector2) const
> Returns the normalized vector pointing from this vector to to. This is equivalent to using (b - a).normalized().

使用例: Enemy が Player に向かって移動したい時
gd
func _physics_process(delta: float) -> void: var direction := position.direction_to(player.position) velocity = speed * direction move_and_slide()
direction_to は、以下の処理と同じ
var direction := (player.position - position).normalized()
今までこの書き方をすることが多かったので、今後は direction_to() を使う