Godot Version
godot 4.7.2
Question
Ive finally fixed my previous issue but now somethings wrong with the global position
extends CharacterBody3D
@export var WalkSpeed: float = 1.5
@export var RunSpeed: float = 4.0
@export var AttackReach: float = 1.5
@onready var navigation_agent: NavigationAgent3D = $NavigationAgent3D
var player: CharacterBody3D = null
func _ready() -> void:
var players = get_tree().get_nodes_in_group("player")
if players.size() > 0:
var player = players[0]
print("found player:", player.name)
func _process(delta: float) -> void:
navigation_agent.set_target_position(player.global_position)
if global_position.distance_to(player.global_position) < AttackReach:
var attack: Attack = Attack.new(1.0, self)
player.health_component.damage(attack)
func _physics_process(_delta: float) -> void:
process_move()
func process_move() -> void:
#if navigation_agent.is_navigation_finished():
#return
#var next_position: Vector3 = navigation_agent.get_next_path_position()
#velocity = global_position.direction_to(next_position) * WalkSpeed
move_and_slide()
func on_death() -> void:
queue_free()