fix: make 2d example boid sprite direction accurate

This commit is contained in:
dusk 2024-12-06 23:06:15 +03:00
parent b30b0ef5e4
commit d33d4e99b8
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw

View File

@ -13,9 +13,8 @@ script/source = "extends Sprite2D
@onready var boid: Boid2D = get_parent() @onready var boid: Boid2D = get_parent()
func _process(delta: float) -> void: func _process(delta: float) -> void:
var dir := boid.get_velocity().normalized() var dir_target := boid.global_position + boid.get_velocity()
var target_rot := atan2(dir.y, dir.x) look_at(dir_target)
rotation = move_toward(rotation, target_rot, delta * PI * 2.0 * absf(target_rot - rotation))
" "
[node name="ExampleBoid" type="Boid2D"] [node name="ExampleBoid" type="Boid2D"]