Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | mrdanb |
the code:
extends CharacterBody2D
const speed = 200
@export var player: Node2D
@export var marker: Node2D
@onready var nav_agent := $NavigationAgent2D as NavigationAgent2D
func _physics_process(_delta: float) -> void:
var dir = to_local(nav_agent.get_next_path_position()).normalized()
velocity = dir * speed
move_and_slide()
func makepath() -> void:
if Golbal.marker_finder == 0:
nav_agent.target_position = player.global_position
else:
nav_agent.target_position = marker.global_position
func _on_timer_timeout():
makepath()
func _on_area_2d_body_entered(body):
if body.is_in_group("player"):
Golbal.marker_finder -= 1
func _on_area_2d_body_exited(body):
if body.is_in_group("player"):
Golbal.marker_finder += 1
@spaceyjase - you can always copy/paste this to an answer and then Hide the original comment… That’d actually be preferable for the board, since the question does have an answer…
jgodfrey | 2023-07-07 22:45