more AI work
This commit is contained in:
@@ -6,6 +6,7 @@ var heartbeat : float = 3.0
|
||||
@export var initial_wait_time : float = 1.0
|
||||
@export var between_shot_time : Vector2 = Vector2(.5,2.0)
|
||||
@export var reload_time : float = 7.0
|
||||
@export var alarm_sound : AudioStreamPlayer3D
|
||||
|
||||
|
||||
var ammo
|
||||
@@ -18,9 +19,10 @@ func Enter():
|
||||
ammo = enemy.max_ammo
|
||||
enemy.turret_material.emission_enabled = true
|
||||
initial_timer = initial_wait_time
|
||||
alarm_sound.play()
|
||||
|
||||
func update_waypoint():
|
||||
enemy.nav_agent.set_target_position(enemy.character_follow.global_position)
|
||||
enemy.nav_agent.set_target_position(enemy.point_of_interest)
|
||||
|
||||
func Update(delta):
|
||||
if heartbeat > 0:
|
||||
@@ -46,7 +48,7 @@ func Update(delta):
|
||||
Transitioned.emit(self,"reload")
|
||||
|
||||
func Physics_Update(delta):
|
||||
enemy.turret_look_next.look_at(enemy.character_follow.global_position)
|
||||
enemy.turret_look_next.look_at(enemy.point_of_interest)
|
||||
enemy.turret_look.rotation = lerp(enemy.turret_look.rotation,enemy.turret_look_next.rotation,delta * enemy.turret_look_speed)
|
||||
|
||||
var destination = enemy.nav_agent.get_next_path_position()
|
||||
|
||||
@@ -2,14 +2,9 @@ extends State
|
||||
class_name EnemyState
|
||||
|
||||
@export var enemy : CharacterBody3D
|
||||
@export var enemy_targets : Array[Area3D]
|
||||
@export var move_speed : float = 3
|
||||
@export var can_see : bool = false
|
||||
@export var can_see : bool = false # indicates whether the enemy is able to see things in the state
|
||||
|
||||
func Enter():
|
||||
if enemy_targets != null:
|
||||
for target in enemy_targets:
|
||||
target.body_part_hit.connect(take_damage)
|
||||
|
||||
func Update(delta):
|
||||
if enemy.visibility_areas != null:
|
||||
@@ -17,28 +12,15 @@ func Update(delta):
|
||||
var bodies = area.get_overlapping_bodies()
|
||||
if bodies != null:
|
||||
for i in bodies:
|
||||
enemy.point_of_interest = i.global_position
|
||||
if i is Player:
|
||||
enemy.character_follow = i
|
||||
else:
|
||||
enemy.point_of_interest = null
|
||||
enemy.character_follow = null
|
||||
|
||||
if enemy.point_of_interest != null:
|
||||
enemy.line_of_sight_ray.look_at(enemy.point_of_interest)
|
||||
if enemy.line_of_sight_ray.is_colliding():
|
||||
if enemy.line_of_sight_ray.get_collider() is Player:
|
||||
if can_see:
|
||||
enemy.character_follow = enemy.line_of_sight_ray.get_collider()
|
||||
Transitioned.emit(self,"attack")
|
||||
if enemy.character_follow != null:
|
||||
if can_see:
|
||||
if enemy.is_player_visible():
|
||||
print("PLAYER SPOTTED")
|
||||
enemy.cache_player_pos()
|
||||
Transitioned.emit(self,"attack")
|
||||
|
||||
|
||||
func take_damage(dam,bullet_damage):
|
||||
SignalBus.emit_signal("enemy_hit")
|
||||
enemy.health -= dam * bullet_damage
|
||||
enemy.health_bar_sprite.visible = true
|
||||
enemy.health_bar_sprite.health_update()
|
||||
var number_spawn = enemy.damage_number.instantiate()
|
||||
number_spawn.damage_amt = bullet_damage * dam
|
||||
number_spawn.position = enemy.global_position + Vector3(0,2,0)
|
||||
get_tree().get_root().add_child(number_spawn)
|
||||
|
||||
if enemy.health <= 0:
|
||||
Transitioned.emit(self,"die")
|
||||
|
||||
@@ -7,5 +7,5 @@ signal body_part_hit(dam,bullet_damage)
|
||||
func hit(bullet_damage):
|
||||
emit_signal("body_part_hit", damage, bullet_damage)
|
||||
|
||||
func _on_body_entered(body: Node3D) -> void:
|
||||
hit(body.bullet_damage)
|
||||
#func _on_body_entered(body: Node3D) -> void:
|
||||
#hit(body.bullet_damage)
|
||||
|
||||
@@ -34,6 +34,7 @@ func _physics_process(delta: float) -> void:
|
||||
collision_ray_length_adj()
|
||||
|
||||
func damage(body):
|
||||
print("BODY HIT : ",body)
|
||||
if body != null and !body.is_in_group("player"):
|
||||
|
||||
if collision_raycast_3d != null:
|
||||
|
||||
@@ -11,6 +11,7 @@ var last_enemy : bool = false
|
||||
@export var max_ammo = 10
|
||||
@export var loot_amount = 2
|
||||
@export var nav_agent : NavigationAgent3D
|
||||
@export var hit_targets : Array[Area3D]
|
||||
@export var visibility_areas : Array[Area3D]
|
||||
@export var line_of_sight_ray : RayCast3D
|
||||
|
||||
@@ -71,14 +72,14 @@ var hive_velocity
|
||||
var hive_nav_point
|
||||
var dying
|
||||
var can_die : bool = false
|
||||
var player_in_view = false
|
||||
var player_last_seen
|
||||
var knocked = false
|
||||
var stunned = false
|
||||
var health
|
||||
|
||||
|
||||
var point_of_interest
|
||||
var character_follow
|
||||
var player_last_seen
|
||||
|
||||
func _ready():
|
||||
health = start_health
|
||||
@@ -90,12 +91,49 @@ func _ready():
|
||||
await get_tree().create_timer(random_time).timeout
|
||||
postfire_timer.start()
|
||||
|
||||
if hit_targets != null:
|
||||
for target in hit_targets:
|
||||
target.body_part_hit.connect(take_damage)
|
||||
|
||||
func _process(delta):
|
||||
move_and_slide()
|
||||
look_at_player()
|
||||
cache_player_pos()
|
||||
|
||||
func stun():
|
||||
state_machine.on_child_transition(state_machine.current_state,"stunned")
|
||||
change_state_to("stunned")
|
||||
|
||||
func take_damage(dam,bullet_damage):
|
||||
SignalBus.emit_signal("enemy_hit")
|
||||
health -= dam * bullet_damage
|
||||
health_bar_sprite.visible = true
|
||||
health_bar_sprite.health_update()
|
||||
var number_spawn = damage_number.instantiate()
|
||||
number_spawn.damage_amt = bullet_damage * dam
|
||||
number_spawn.position = global_position + Vector3(0,2,0)
|
||||
get_tree().get_root().add_child(number_spawn)
|
||||
|
||||
if health <= 0:
|
||||
change_state_to("die")
|
||||
|
||||
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)
|
||||
|
||||
func is_player_visible():
|
||||
if line_of_sight_ray.is_colliding():
|
||||
if line_of_sight_ray.get_collider() is Player:
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
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()
|
||||
|
||||
func save():
|
||||
var save_dict = {
|
||||
|
||||
Reference in New Issue
Block a user