ai refactoring

This commit is contained in:
2026-05-22 00:06:23 +02:00
parent b22f219a5e
commit 0c237430ea
10 changed files with 67 additions and 68 deletions

View File

@@ -2,7 +2,7 @@ extends CharacterBody3D
class_name AIBase
@export_group("Movement")
@export_group("Settings")
@export var speed: float = 4.0
var _enable_state_machine: bool = true
@export var enable_state_machine: bool:
@@ -11,13 +11,8 @@ var _enable_state_machine: bool = true
toggle_enable_state_machine()
get:
return _enable_state_machine
@export var anim_player: AnimationPlayer
@onready var patrol_radius_shape: CollisionShape3D = $%PatrolRadiusShape
@onready var nav_agent: NavigationAgent3D = $%NavigationAgent3D
@onready var state_machine: StateMachine = $%StateMachine
@export_group("Entities")
enum EntityType { HUMANOID, ANIMAL }
@export var entity_type: EntityType = EntityType.HUMANOID
@@ -25,6 +20,9 @@ enum EntityType { HUMANOID, ANIMAL }
@export var allowed_biomes: Array[String] = []
@export_range(0.0, 100.0, 0.1) var spawn_uniqueness: float = 1.0
@onready var patrol_radius_shape: CollisionShape3D = $%PatrolRadiusShape
@onready var nav_agent: NavigationAgent3D = $%NavigationAgent3D
@onready var state_machine: StateMachine = $%StateMachine
func _ready() -> void:
randomize()
@@ -63,15 +61,3 @@ func navigate_to_random_point() -> void:
var target_point_in_space = global_position + Vector3(randf_range(-1, 1), 0, randf_range(-1, 1)).normalized() * randf_range(0, patrol_radius)
var closest_valid_point = NavigationServer3D.map_get_closest_point(nav_map_rid, target_point_in_space)
nav_agent.target_position = closest_valid_point
func run_walking_animation() -> void:
if anim_player and anim_player.has_animation("custom/walking"):
var anim = anim_player.get_animation("custom/walking")
anim.loop_mode = Animation.LOOP_LINEAR
anim_player.play("custom/walking")
func run_idle_animation() -> void:
if anim_player and anim_player.has_animation("custom/idle"):
var anim = anim_player.get_animation("custom/idle")
anim.loop_mode = Animation.LOOP_LINEAR
anim_player.play("custom/idle")