Enemy move towards player and damage it until player dies or out of range

Hi. I made a RigidBody2D named Zombie 1, I have a basic script to it, one which shows it’s health and one that plays it’s idle animation. I want it to move towards CharacterBody2D named main_character and damage it until it dies or is out of range.
Here is the script

extends RigidBody2D
var health = 50
@onready var zombie_health = $zombie_health

func _ready():
	var mob_types = $AnimatedSprite2D.sprite_frames.get_animation_names()
	$AnimatedSprite2D.play(mob_types[randi() % mob_types.size()])
	zombie_health.text = str(int(health))
func _on_visible_on_screen_notifier_2d_screen_exited():
	queue_free()

Képernyőkép 2024-08-13 130429

Here is a tutorial for the movement:

It’s the most simplest form, without using a navigation agent.

This one is more advanced: https://www.youtube.com/watch?v=Ykz7W9BHzPg
The zombie will move using a navigation agent and a navigation region

I’m not sure if the tutorial includes attacking the player, but you will need an if statement like:

if Vector2(enemy.global_position).distance_to(targeted_player.global_position) <= mob.melee_range: