extends CharacterBody2D; @export var speed = 600 var ac = 7; var SpriteTurningSpeed = 5 @export var FrictionMult = 0 var player_chase = false; var patrolpoint_cur = 0; @export var nav: NavigationAgent2D var player = null; @onready var Player = get_tree().get_first_node_in_group("player") @export var patrolpoints: Array[Node2D]; @onready var timer = $Timer func _physics_process(delta: float) -> void: var direction = Vector2(0,0) if (player_chase): nav.target_position = player.global_position; else: if(patrolpoints[patrolpoint_cur] != null): nav.target_position = patrolpoints[patrolpoint_cur].global_position; else: print("wot") nav.target_position = Vector2(0,0) direction = nav.get_next_path_position() - global_position; direction = direction.normalized(); velocity = velocity.lerp(direction * speed, ac * delta) if velocity.length() > 0.1: rotation = rotate_toward(rotation,velocity.angle(),delta*SpriteTurningSpeed) #print("PlayerChase: " + str(player_chase)) if(patrolpoints[patrolpoint_cur] != null): if(position.distance_to(patrolpoints[patrolpoint_cur].global_position) < 10): print(patrolpoint_cur) patrolpoint_cur += 1 if(patrolpoint_cur == patrolpoints.size()): patrolpoint_cur = 0; move_and_slide(); func _on_dictection_body_entered(body: Node2D) -> void: if(body.is_in_group("player")): timer.start(5) player = body; player_chase = true; func _on_dictection_body_exited(body: Node2D) -> void: if(body.is_in_group("player")) && timer.is_stopped(): player = null; player_chase = false; func _on_colltion_body_entered(body: Node2D) -> void: if(body.is_in_group("player")): body.kill()