2024-10-15 21:32:01 +02:00
|
|
|
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
|
|
|
|
|
2024-10-15 21:46:44 +02:00
|
|
|
@onready var geometry: Node3D = null
|
2024-10-15 21:32:01 +02:00
|
|
|
@onready var player_detection: Area3D = %PlayerDetection
|
2024-10-15 21:46:44 +02:00
|
|
|
@onready var default_geometry: Node3D = %DefaultGeometry
|
|
|
|
@onready var animation_player: AnimationPlayer = %AnimationPlayer
|
2024-10-15 21:32:01 +02:00
|
|
|
|
|
|
|
const SPEED = 5.0
|
|
|
|
const JUMP_VELOCITY = 4.5
|
|
|
|
|
2024-11-01 18:07:23 +01:00
|
|
|
var tool_damage:bool = false
|
2024-10-15 21:32:01 +02:00
|
|
|
var tracking_node:Node3D = null
|
2024-11-15 11:35:37 +01:00
|
|
|
|
2024-10-15 21:32:01 +02:00
|
|
|
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
|
2024-10-15 21:46:44 +02:00
|
|
|
geometry = find_child("Geometry")
|
|
|
|
|
|
|
|
if geometry == null:
|
|
|
|
geometry = default_geometry
|
|
|
|
else:
|
|
|
|
default_geometry.visible = false
|
|
|
|
animation_player.set_root("Geometry")
|
2024-10-15 21:32:01 +02:00
|
|
|
|
|
|
|
func _on_player_detection_body_entered(body: Node3D) -> void:
|
2024-11-15 11:35:37 +01:00
|
|
|
if body is Player:
|
|
|
|
tracking_node = body
|
2024-10-15 21:32:01 +02:00
|
|
|
|
|
|
|
func _on_player_detection_body_exited(body: Node3D) -> void:
|
|
|
|
if body == tracking_node:
|
|
|
|
tracking_node = null
|