Pathfinding is not working properly

Godot 4.5.1

he is not doing his job and just runs in place like an idiot

extends CharacterBody3D
var asleep = true
var animations = ["idle1", "idle2"]
var deaths = ["die01", "die02"]
var health = 60
var player:CharacterBody3D
var hasdied = false
const SPEED = 5.0
func _process(delta: float) -> void:
	if health <= 0:
		if !hasdied:
			$runner/AnimationPlayer.stop()
			hasdied = true
			$runner/Armature/Skeleton3D/BoneAttachment3D/Die.play()
			$runner/AnimationPlayer.play(deaths.pick_random())
	else:
		if !hasdied:
			if asleep:
				velocity = Vector3.ZERO
				if !$runner/AnimationPlayer.is_playing():
					$runner/AnimationPlayer.play(animations.pick_random())
			else:
				if !$runner/AnimationPlayer.is_playing():
					$NavigationAgent3D.target_position = player.global_position
					$runner/AnimationPlayer.play("run_001")
func _physics_process(delta: float) -> void:
	velocity += get_gravity() * delta
func _on_detection_range_body_entered(body: Node3D) -> void:
	if body.is_in_group("player"):
		$runner/AnimationPlayer.stop()
		$runner/Armature/Skeleton3D/BoneAttachment3D/Scream.play()
		asleep = false
		player = body
func hurt(amt:int):
	health -= amt

This is not helpful information what so ever.
What do you expect to happen vs. what actually happens? How are your nodes set up? Do you get any error or warning messages?

1 Like

A video showing the resulting idiocy would also be helpful (and funny) :grinning_face_with_smiling_eyes:.

1 Like


user now may see why it sucks (i’m not hungarian)

1 Like

You are neither setting the velocity nor calling move_and_slide() in your code.

extends CharacterBody3D
var asleep = true
var animations = ["idle1", "idle2"]
var deaths = ["die01", "die02"]
var health = 60
var player:CharacterBody3D
var hasdied = false
const SPEED = 5.0
func _process(delta: float) -> void:
	if health <= 0:
		if !hasdied:
			$runner/AnimationPlayer.stop()
			hasdied = true
			$runner/Armature/Skeleton3D/BoneAttachment3D/Die.play()
			$CollisionShape3D.disabled = true
			$runner/AnimationPlayer.play(deaths.pick_random())
func _physics_process(delta: float) -> void:
	if !hasdied:
		velocity += get_gravity() * delta
	if health > 0:
		if !hasdied:
			if asleep:
				velocity = Vector3.ZERO
				if !$runner/AnimationPlayer.is_playing():
					$runner/AnimationPlayer.play(animations.pick_random())
			else:
				if !$runner/AnimationPlayer.is_playing():
					$NavigationAgent3D.target_position = player.global_transform.origin
					var current = global_transform.origin
					var nextpos = $NavigationAgent3D.get_next_path_position()
					var direction = (nextpos - current).normalized()
					velocity = direction * SPEED
					$runner/AnimationPlayer.play("run_001")
	move_and_slide()
func _on_detection_range_body_entered(body: Node3D) -> void:
	if body.is_in_group("player"):
		$runner/AnimationPlayer.stop()
		$runner/Armature/Skeleton3D/BoneAttachment3D/Scream.play()
		asleep = false
		player = body
func hurt(amt:int):
	health -= amt

```after tweaking and refactoring it it still doesn't work

nvm it works somehow

i take it back it still is quite bad

extends CharacterBody3D
var asleep = true
var animations = ["idle1", "idle2"]
var deaths = ["die01", "die02"]
var health = 60
var player:CharacterBody3D
var hasdied = false
const SPEED = 7.0
func _process(delta: float) -> void:
	if health <= 0:
		if !hasdied:
			$runner/AnimationPlayer.stop()
			hasdied = true
			$runner/Armature/Skeleton3D/BoneAttachment3D/Die.play()
			$CollisionShape3D.disabled = true
			$runner/AnimationPlayer.play(deaths.pick_random())
func _physics_process(delta: float) -> void:
	if !hasdied:
		velocity += get_gravity() * delta
	if health > 0:
		if !hasdied:
			if asleep:
				velocity = Vector3.ZERO
				if !$runner/AnimationPlayer.is_playing():
					$runner/AnimationPlayer.play(animations.pick_random())
			else:
				if !$runner/AnimationPlayer.is_playing():
					$NavigationAgent3D.target_position = player.global_transform.origin
					var current = global_transform.origin
					var nextpos = $NavigationAgent3D.get_next_path_position()
					var direction = (nextpos - current).normalized()
					velocity = direction * SPEED
					$runner/AnimationPlayer.play("run_001")
	else:
		velocity = Vector3.ZERO
	move_and_slide()
func _on_detection_range_body_entered(body: Node3D) -> void:
	if body.is_in_group("player") && !hasdied:
		$runner/AnimationPlayer.stop()
		$runner/Armature/Skeleton3D/BoneAttachment3D/Scream.play()
		asleep = false
		player = body
		$updatetimer.start(1.0)
func hurt(amt:int):
	health -= amt
func _on_updatetimer_timeout() -> void:
	updatepath()
	$updatetimer.start(1.0)
func updatepath():
	$NavigationAgent3D.target_position = player.global_transform.origin