pretty happy with basic AI behavior
This commit is contained in:
@@ -1,61 +1,41 @@
|
||||
extends EnemyState
|
||||
class_name EnemySearch
|
||||
|
||||
@export var idle_speed : float = 1.5
|
||||
var search_timer
|
||||
|
||||
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
|
||||
const SEARCH_TIME_MAX : float = 10.0
|
||||
|
||||
func Enter():
|
||||
super()
|
||||
search_point()
|
||||
scan_direction = deg_to_rad(TURRET_TURN_AMT)
|
||||
search_timer = SEARCH_TIME_MAX
|
||||
|
||||
func Update(delta: float):
|
||||
super(delta)
|
||||
|
||||
attack_on_sight()
|
||||
|
||||
if search_time > 0:
|
||||
search_time -= delta
|
||||
if search_timer > 0:
|
||||
search_timer -= delta
|
||||
else:
|
||||
Transitioned.emit(self,"idle")
|
||||
|
||||
if scan_time > 0:
|
||||
scan_time -= delta
|
||||
else:
|
||||
randomize_turret_scan()
|
||||
attack_on_sight()
|
||||
search_point()
|
||||
|
||||
if enemy.global_position.distance_to(move_target_adj()) < 1:
|
||||
Transitioned.emit(self,"idle")
|
||||
|
||||
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")
|
||||
#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())
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user