Godot Version
`4.3
Question
following a tutorial to let a bat fly but mine doesnt work here is the code:
extends CharacterBody2D
const speed = 30
var dir: Vector2
var is_bat_chase: bool
func _ready():
is_bat_chase = false
func _process(delta):
move(delta)
handle_animation()
func move(delta):
if !is_bat_chase:
velocity += dir * speed * delta
move_and_slide()
func _on_timer_timeout() → void:
$Timer.wait_time = choose([1.0, 1.5, 2.0])
if !is_bat_chase:
dir = choose([Vector2.RIGHT, Vector2.UP, Vector2.LEFT, Vector2.DOWN])
print(dir)
func handle_animation():
var animated_sprite = $AnimatedSprite2D
animated_sprite.play(“fly”)
if dir.x == -1:
animated_sprite.flip_h = true
elif dir.x == 1:
animated_sprite.flip_h = false
func choose(array):
array.shuffle()
return array.front()