32 lines
933 B
GDScript
32 lines
933 B
GDScript
extends EnemyState
|
|
class_name EnemyAttack
|
|
|
|
var heartbeat : float = 3.0
|
|
|
|
@onready var player = get_tree().current_scene.player
|
|
|
|
func _Enter():
|
|
update_waypoint()
|
|
|
|
func update_waypoint():
|
|
enemy.nav_agent.set_target_position(player.global_position)
|
|
|
|
func Update(delta):
|
|
if heartbeat > 0:
|
|
heartbeat -= delta
|
|
else:
|
|
update_waypoint()
|
|
|
|
func Physics_Update(delta):
|
|
enemy.turret_look_next.look_at(player.global_position)
|
|
enemy.turret_look.look_at(player.global_position)
|
|
|
|
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 * move_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)
|