59 lines
1.5 KiB
GDScript
59 lines
1.5 KiB
GDScript
extends EnemyState
|
|
class_name EnemyIdle
|
|
|
|
@export var idle_speed : float = 1.5
|
|
|
|
var move_direction : Vector3
|
|
var scan_direction : float
|
|
|
|
var wander_time : float
|
|
var scan_time : float
|
|
|
|
const WANDER_AMT = 50
|
|
const TURRET_TURN_AMT : float = 90.0
|
|
const TURRET_SCAN_SPEED : float = .5
|
|
|
|
func randomize_wander():
|
|
var x = randf_range(-WANDER_AMT,WANDER_AMT)
|
|
var z = randf_range(-WANDER_AMT,WANDER_AMT)
|
|
move_direction = enemy.global_position + Vector3(x,0,z)
|
|
enemy.nav_agent.set_target_position(move_direction)
|
|
wander_time = randf_range(1,3)
|
|
|
|
func randomize_turret_scan():
|
|
scan_direction = -scan_direction
|
|
enemy.turret_look_next.rotation = Vector3(0,scan_direction,0)
|
|
scan_time = randf_range(5,10)
|
|
|
|
func Enter():
|
|
super()
|
|
randomize_wander()
|
|
scan_direction = deg_to_rad(TURRET_TURN_AMT)
|
|
|
|
func Update(delta: float):
|
|
super(delta)
|
|
|
|
attack_on_sight()
|
|
|
|
if wander_time > 0:
|
|
wander_time -= delta
|
|
else:
|
|
randomize_wander()
|
|
|
|
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.global_rotation.y = rotate_to_face2D(enemy,destination,delta,turret_speed)
|