Enemy follows player with zig zag walk

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lucasfazzi

Hi guys;

I have a default enemy follow code for my default enemy character that is:

extends KinematicBody2D

const MOVE_SPEED = 180
var ENEMY_1_LIFE = 100

onready var player = get_parent().get_node("player")

func _physics_process(delta):
    var vec_to_player = player.global_position - global_position
    vec_to_player = vec_to_player.normalized()
    global_rotation = atan2(vec_to_player.y, vec_to_player.x)
    move_and_collide(vec_to_player * MOVE_SPEED * delta)

I was thinking if it is possible to adapt this default code and make enemy follows player with a zig zag walk just changing some positions, or the best way is using some PathFollow2D.

Thanks guys.

PS: I’m learning how to format posts in the godot forum; if it’s a bit confuse, please tell me to edit