42 lines
1.0 KiB
GDScript
42 lines
1.0 KiB
GDScript
extends EnemyState
|
|
class_name EnemySearch
|
|
|
|
var search_timer
|
|
|
|
const SEARCH_TIME_MAX : float = 10.0
|
|
|
|
func Enter():
|
|
super()
|
|
search_point()
|
|
search_timer = SEARCH_TIME_MAX
|
|
|
|
func Update(delta: float):
|
|
super(delta)
|
|
|
|
if search_timer > 0:
|
|
search_timer -= delta
|
|
else:
|
|
Transitioned.emit(self,"idle")
|
|
|
|
attack_on_sight()
|
|
search_point()
|
|
|
|
if enemy.global_position.distance_to(move_target_adj()) < 1:
|
|
Transitioned.emit(self,"idle")
|
|
|
|
func Physics_Update(delta : float):
|
|
#turret transform
|
|
enemy.turret_look_next.look_at(move_target())
|
|
enemy.turret_look.rotation = lerp(enemy.turret_look.rotation,enemy.turret_look_next.rotation,delta * turret_speed)
|
|
|
|
var destination = enemy.nav_agent.get_next_path_position()
|
|
var local_destination = destination - enemy.global_position
|
|
var direction = local_destination.normalized()
|
|
|
|
enemy.velocity = direction * move_speed
|
|
enemy.global_rotation.y = rotate_to_face2D(enemy,move_target(),delta,turret_speed)
|
|
|
|
|
|
func search_point():
|
|
enemy.nav_agent.set_target_position(move_target())
|