62 lines
1.6 KiB
GDScript
62 lines
1.6 KiB
GDScript
extends EnemyState
|
|
class_name EnemySearch
|
|
|
|
@export var idle_speed : float = 1.5
|
|
|
|
var move_direction : Vector3
|
|
var scan_direction : float
|
|
|
|
var search_time : float
|
|
var scan_time : float
|
|
|
|
const WANDER_AMT = 50
|
|
const TURRET_TURN_AMT : float = 90.0
|
|
const TURRET_SCAN_SPEED : float = .5
|
|
|
|
func Enter():
|
|
super()
|
|
search_point()
|
|
scan_direction = deg_to_rad(TURRET_TURN_AMT)
|
|
|
|
func Update(delta: float):
|
|
super(delta)
|
|
|
|
attack_on_sight()
|
|
|
|
if search_time > 0:
|
|
search_time -= delta
|
|
else:
|
|
Transitioned.emit(self,"idle")
|
|
|
|
if scan_time > 0:
|
|
scan_time -= delta
|
|
else:
|
|
randomize_turret_scan()
|
|
|
|
func Physics_Update(delta : float):
|
|
if enemy:
|
|
#turret transform
|
|
enemy.turret_look.rotation = lerp(enemy.turret_look.rotation,enemy.turret_look_next.rotation,delta * TURRET_SCAN_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 * idle_speed
|
|
enemy.spider_look_next.look_at(destination)
|
|
var look_target = enemy.spider_look_next.global_rotation.y
|
|
enemy.global_rotation.y = lerp(enemy.global_rotation.y,look_target,delta * 3)
|
|
|
|
|
|
if enemy.turret_look.is_colliding() and enemy.turret_look.get_collider() is Player:
|
|
Transitioned.emit(self,"attack")
|
|
|
|
func search_point():
|
|
enemy.nav_agent.set_target_position(move_target())
|
|
search_time = randf_range(3,10)
|
|
|
|
func randomize_turret_scan():
|
|
scan_direction = -scan_direction
|
|
enemy.turret_look_next.rotation = Vector3(0,scan_direction,0)
|
|
scan_time = randf_range(5,10)
|