I'm trying to get my enemy "wander" state to wait a random amount before going back to moving?
I'm going crazy because this code semi-worked until I started trying to use timers to make the enemy "wait" before deciding a new target location:
if direction == Vector2():
direction = global_position.direction_to(target_position)
if global_position.distance_to(target_position) <= 12: # If withing 12 units of the destination, wait and then get a new destination
direction = Vector2(0,0)
await get_tree().create_timer(1).timeout
target_position == get_wander_location()
direction = global_position.direction_to(target_position)
await get_tree().create_timer(1).timeout
target_position == get_wander_location()
if velocity == Vector2(0,0) and direction == Vector2(0,0): # because these were printing 0,0 randomly
target_position == get_wander_location()
direction = global_position.direction_to(target_position)```
Additional explanation: get_wander_location() returns a point within 32 units of the spawn location (simply the global_location when the node is ready)