TinyAdventure/objects/non_player_character.gd

43 lines
1.1 KiB
GDScript

class_name NonPlayerCharacter
extends CharacterBody3D
@export var reacts_to_player:bool = true :
set (value):
reacts_to_player = _set_reacts_to_player(value)
get:
return reacts_to_player
@onready var geometry: Node3D = null
@onready var player_detection: Area3D = %PlayerDetection
@onready var default_geometry: Node3D = %DefaultGeometry
@onready var animation_player: AnimationPlayer = %AnimationPlayer
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
var tool_damage:bool = false
var tracking_node:Node3D = null
func _set_reacts_to_player(value:bool) -> bool:
if player_detection != null:
player_detection.monitoring = value
return value
func _ready() -> void:
player_detection.monitoring = reacts_to_player
geometry = find_child("Geometry")
if geometry == null:
geometry = default_geometry
else:
default_geometry.visible = false
animation_player.set_root("Geometry")
func _on_player_detection_body_entered(body: Node3D) -> void:
if body is Player:
tracking_node = body
func _on_player_detection_body_exited(body: Node3D) -> void:
if body == tracking_node:
tracking_node = null