Making an AI "zig zag" toward player
Hello, I would like to make my AI enemy zig zag as it moves toward the player after it sees them. I have a function that proves if it is allowed to move, find the direction of the player, then moves toward them. However, as the enemy moves toward the player I would like it to make a short pause then move toward the player but at an oblique angle. My only idea so far is to generate a random number then someone add/subtract it to the rotation angle of the enemy on the Y axis, but it's not working out for me since you can't add integers to Vector3 numbers. Here is my function so far:
func move_to_target(delta): if move == true: while i < 3: var r = RandomNumberGenerator.new() r.randomize() var mrn = r.randi_range(-30, 30) move_and_slide(direction * speed * delta, Vector3.UP) yield(get_tree().create_timer(pause), "timeout") i = i + 1 state = ALERT
I would like to add a line after the timer for the new direction. I'm very new so if there is a better/more obvious way to do this I'm all ears.