improvements to ai but still needs a lot of work
This commit is contained in:
@@ -5,6 +5,7 @@ signal last_enemy_dead()
|
||||
|
||||
var player
|
||||
var last_enemy : bool = false
|
||||
@export var debug_tools : bool = false
|
||||
@export var start_health = 3
|
||||
@export var SPEED = 3.0
|
||||
@export var turret_look_speed = 6
|
||||
@@ -60,6 +61,8 @@ $body/bodyoutline]
|
||||
@onready var health_bar_sprite: Sprite3D = $HealthBarSprite
|
||||
@onready var servo_single: AudioStreamPlayer3D = $AUIDO/ServoSingle
|
||||
@onready var servo_loop: AudioStreamPlayer3D = $AUIDO/ServoLoop
|
||||
@onready var debug_tracker: Node3D = $DebugTracker
|
||||
@onready var line_of_sight: RayCast3D = $LineOfSight
|
||||
|
||||
|
||||
var gravity = 9.8
|
||||
@@ -77,9 +80,10 @@ var stunned = false
|
||||
var health
|
||||
var ammo
|
||||
|
||||
var point_of_interest
|
||||
var line_of_sight_target
|
||||
var character_follow
|
||||
var player_last_seen
|
||||
var points_of_interest
|
||||
|
||||
func _ready():
|
||||
health = start_health
|
||||
@@ -97,9 +101,13 @@ func _ready():
|
||||
target.body_part_hit.connect(take_damage)
|
||||
|
||||
func _process(delta):
|
||||
line_of_sight.global_position = global_position
|
||||
move_and_slide()
|
||||
look_at_player()
|
||||
cache_player_pos()
|
||||
|
||||
if debug_tools:
|
||||
debug_marker()
|
||||
|
||||
func stun():
|
||||
change_state_to("stunned")
|
||||
@@ -121,8 +129,8 @@ func change_state_to(set_state):
|
||||
state_machine.on_child_transition(state_machine.current_state,set_state)
|
||||
|
||||
func look_at_player():
|
||||
if character_follow != null:
|
||||
line_of_sight_ray.look_at(character_follow.global_position)
|
||||
if line_of_sight_target != null:
|
||||
line_of_sight_ray.look_at(line_of_sight_target.global_position)
|
||||
|
||||
func is_player_visible():
|
||||
if line_of_sight_ray.is_colliding():
|
||||
@@ -138,6 +146,8 @@ func is_player_in_area():
|
||||
if bodies != null:
|
||||
for i in bodies:
|
||||
if i is Player:
|
||||
if line_of_sight_target == null:
|
||||
line_of_sight_target = i
|
||||
return true
|
||||
|
||||
return false
|
||||
@@ -145,7 +155,14 @@ func is_player_in_area():
|
||||
func cache_player_pos():
|
||||
if line_of_sight_ray.is_colliding():
|
||||
if line_of_sight_ray.get_collider() is Player:
|
||||
point_of_interest = line_of_sight_ray.get_collision_point()
|
||||
player_last_seen = line_of_sight_ray.get_collision_point()
|
||||
|
||||
func debug_marker():
|
||||
if player_last_seen != null:
|
||||
debug_tracker.visible = true
|
||||
debug_tracker.global_position = player_last_seen
|
||||
else:
|
||||
debug_tracker.visible = false
|
||||
|
||||
func save():
|
||||
var save_dict = {
|
||||
|
||||
Reference in New Issue
Block a user