I need help converting Godot 3 navigation code to Godot 4

Godot Version

Godot 4.2.1

Question

Im new to Godot, Im following a tutorial I found on youtube on how to make a Doom clone, the problem is this tutorial is for Godot 3 and Im using Godot 4, I managed to find work arounds for most of the stuff but I have been stuck at the navigation part of it for two days now, I cant find a solution, I need help making this code work in Godot 4.

extends CharacterBody3D

@onready var nav = get_tree().get_nodes_in_group(“NavMesh”)[0];
@onready var player = get_tree().get_nodes_in_group(“Player”)[0];

var path : Array = ; #hold the path coordinates from the enemy to the player.
var path_index: int = 0; #keep track of which coordinate to go to.
var speed = 3;
var health = 20;

func _ready():

pass;
func take_damage (damage_amount):
health -= damage_amount;
if health <= 0:
death();

func _physics_process(delta):
if path_index < path.size():
var direction = (path[path_index] - global_transform.origin);
if direction.length () < 1:
path_index += 1;
else:
velocity = direction.normalized() * speed;
move_and_slide();
else:
find_path(player);

func find_path(target):

path = nav.get_simple_path(global_transform.origin, target);
path_index = 0;

func death():
set_process(false);
set_physics_process(false);
$CollisionShape3D.disabled = true;
if health < -20:
$AnimatedSprite3D.play(“explode”);
else:
$AnimatedSprite3D.play(“die”);
func shoot(target):
pass;

The problem is that the function “get_simple_path” does not exist anymore.

That tutorial must be ancient considering that get_simple_path() is even outdated in Godot 3 and completely removed in Godot 4.

Replace it with NavigationServer map_get_path() function. You need the navigation map RID for that. Examples you can find here Using NavigationPaths — Godot Engine (latest) documentation in English