Godot Version
4.4.1
Question
Hello,
anyone know the best way to make an enemy chase the player ?
Ive messed with the NavigationRegion2D node, but something doesnt seem right,
In NavigationRegion2D, i cant draw the polygon manually, or edit the points in the holes manually !
for some reason the enemy jitters and creates spikes in the path
enemy script
extends CharacterBody2D
const SPEED = 200.0
@onready var navigation_agent: NavigationAgent2D = $NavigationAgent2D
@export var targetChase: CharacterBody2D;
func _physics_process(_delta: float) -> void:
if ( targetChase ):
navigation_agent.target_position = targetChase.global_position;
if ( navigation_agent.is_navigation_finished() ):
return
var current_agent_position = global_position;
var next_path_position = navigation_agent.get_next_path_position();
velocity = current_agent_position.direction_to(next_path_position) * SPEED
move_and_slide()