Godot 4.5.1
this idiot either walks like an idiot or doesn’t walk at all
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_position
var current = global_position
var nextpos = $NavigationAgent3D.get_next_path_position()
var direction = (nextpos - current).normalized()
print(current, nextpos, player.global_position)
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
func _on_navigation_agent_3d_path_changed() -> void:
updatepath() # works if this signal is not present for some odd reason
and walks looking directly south