enemy reloads each bullet, added servo sound
This commit is contained in:
57
scripts/EnemyReload.gd
Normal file
57
scripts/EnemyReload.gd
Normal file
@@ -0,0 +1,57 @@
|
||||
extends EnemyState
|
||||
class_name EnemyReload
|
||||
|
||||
@export var reload_time : float = 7.0
|
||||
@export var reload_sound : AudioStreamPlayer3D
|
||||
@export var run_distance : float = 3
|
||||
|
||||
@onready var player = get_tree().current_scene.player
|
||||
|
||||
var heartbeat : float = 3.0
|
||||
var remaining_bullets
|
||||
|
||||
func Enter():
|
||||
super()
|
||||
remaining_bullets = enemy.max_ammo
|
||||
enemy.servo_audio.play()
|
||||
|
||||
func Exit():
|
||||
super()
|
||||
enemy.servo_audio.play()
|
||||
|
||||
func update_waypoint():
|
||||
var direction = (player.global_position - enemy.global_position).normalized()
|
||||
enemy.nav_agent.set_target_position(direction * run_distance)
|
||||
|
||||
func Update(delta):
|
||||
if heartbeat > 0:
|
||||
heartbeat -= delta
|
||||
else:
|
||||
update_waypoint()
|
||||
|
||||
if remaining_bullets > 0:
|
||||
if !reload_sound.is_playing() and !enemy.servo_audio.is_playing():
|
||||
remaining_bullets -= 1
|
||||
reload_sound.play()
|
||||
else:
|
||||
finished_reload()
|
||||
|
||||
|
||||
func Physics_Update(delta):
|
||||
enemy.turret_look_next.look_at(player.global_position)
|
||||
enemy.turret_look.rotation = lerp(enemy.turret_look.rotation,Vector3(deg_to_rad(90),0,0),delta * enemy.turret_look_speed)
|
||||
|
||||
var destination = enemy.nav_agent.get_next_path_position()
|
||||
var local_destination = destination - enemy.global_position
|
||||
var direction = local_destination.normalized()
|
||||
if enemy.global_position.distance_to(local_destination) > 1:
|
||||
enemy.velocity = direction * move_speed
|
||||
enemy.spider_look_next.look_at(player.global_position)
|
||||
var look_target = enemy.spider_look_next.global_rotation.y
|
||||
enemy.global_rotation.y = lerp(enemy.global_rotation.y,look_target,delta * 3)
|
||||
|
||||
func finished_reload():
|
||||
if enemy.turret_look_next.is_colliding() and enemy.turret_look_next.get_collider() is Player:
|
||||
Transitioned.emit(self,"attack")
|
||||
else:
|
||||
Transitioned.emit(self,"idle")
|
||||
Reference in New Issue
Block a user