rudimentary search function. not working right yet
This commit is contained in:
@@ -25,6 +25,10 @@ func update_waypoint():
|
||||
enemy.nav_agent.set_target_position(enemy.point_of_interest)
|
||||
|
||||
func Update(delta):
|
||||
if enemy.point_of_interest != null:
|
||||
if !enemy.is_player_visible():
|
||||
Transitioned.emit(self,"search")
|
||||
|
||||
if heartbeat > 0:
|
||||
heartbeat -= delta
|
||||
else:
|
||||
|
||||
58
scripts/EnemySearch.gd
Normal file
58
scripts/EnemySearch.gd
Normal file
@@ -0,0 +1,58 @@
|
||||
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 search_point():
|
||||
enemy.nav_agent.set_target_position(enemy.point_of_interest)
|
||||
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)
|
||||
|
||||
func Enter():
|
||||
super()
|
||||
search_point()
|
||||
scan_direction = deg_to_rad(TURRET_TURN_AMT)
|
||||
|
||||
func Update(delta: float):
|
||||
super(delta)
|
||||
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")
|
||||
1
scripts/EnemySearch.gd.uid
Normal file
1
scripts/EnemySearch.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dvpf10vdnkfd
|
||||
@@ -20,7 +20,6 @@ func Update(delta):
|
||||
if enemy.character_follow != null:
|
||||
if can_see:
|
||||
if enemy.is_player_visible():
|
||||
print("PLAYER SPOTTED")
|
||||
enemy.cache_player_pos()
|
||||
Transitioned.emit(self,"attack")
|
||||
|
||||
|
||||
@@ -37,3 +37,4 @@ func on_child_transition(state,new_state_name):
|
||||
new_state.Enter()
|
||||
|
||||
current_state = new_state
|
||||
print("STATE CHANGED TO : ",current_state)
|
||||
|
||||
Reference in New Issue
Block a user