Godot Version
4.7.2
Question
I took a break from trying to learn coding so it might be a miner slip up but when I tried testing the chase state for my enemy they wouldn’t move despite the fact that it saw me and knew what to do when it sees me, I thought it was because there was repeated code in the scene with the navigation stuff being in the enemy’s code and the chase state code but when I deleted it like how the tutorial told me the script lost its global_position, does anyone know what to do if not maybe recommend a different tutorial ?
extends State
class_name EnemyChase
@onready var enemy: CharacterBody3D = get_parent().get_parent()
var player: CharacterBody3D = null
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
player = get_tree().get_first_node_in_group("player")
func process(_delta: float) -> void:
enemy.navigation_agent.set_target_position(player.global_position)
if enemy.global_position.distance_to(player.global_position) > enemy.ChaseDistance:
emit_signal("Transitioned", self, "EnemyWander")
func physics_process(_delta: float) -> void:
if enemy.navigation_agent.is_navigation_finished():
return
var next_position: Vector3 = enemy.navigation_agent.get_next_path_position()
enemy.velocity = enemy.global_position.direction_to(next_position) * enemy.RunSpeed