fixed attack in state machine
This commit is contained in:
@@ -1,2 +1,31 @@
|
||||
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)
|
||||
|
||||
@@ -20,7 +20,7 @@ func randomize_wander():
|
||||
|
||||
func randomize_turret_scan():
|
||||
scan_direction = randf_range(-TURRET_TURN_AMT,TURRET_TURN_AMT)
|
||||
scan_time = randf_range(1,3)
|
||||
scan_time = randf_range(5,10)
|
||||
|
||||
func _Enter():
|
||||
randomize_wander()
|
||||
@@ -47,4 +47,7 @@ func Physics_Update(delta : float):
|
||||
var look_target = enemy.spider_look_next.global_rotation.y
|
||||
enemy.global_rotation.y = lerp(enemy.global_rotation.y,look_target,delta * 3)
|
||||
|
||||
enemy.turret.rotation.y = lerp(enemy.turret.rotation.y,deg_to_rad(scan_direction),delta)
|
||||
enemy.turret_look.rotation.y = lerp(enemy.turret_look.rotation.y,deg_to_rad(scan_direction),delta)
|
||||
|
||||
if enemy.turret_look.is_colliding() and enemy.turret_look.get_collider() is Player:
|
||||
Transitioned.emit(self,"attack")
|
||||
|
||||
@@ -8,6 +8,7 @@ func Enter():
|
||||
|
||||
func die():
|
||||
drop_loot()
|
||||
enemy.visible = false
|
||||
#remove from parent array
|
||||
var particlespawn = enemy.die_particles.instantiate()
|
||||
particlespawn.position = enemy.global_position
|
||||
|
||||
@@ -45,10 +45,5 @@ func explode():
|
||||
body.recoil.add_recoil(Vector3(1,.1,.1),10,10)
|
||||
if body.has_method("hit") and !body.is_in_group("player"):
|
||||
body.hit(1)
|
||||
if body.is_in_group("enemy"):
|
||||
body.knocked = true
|
||||
body.stunned = true
|
||||
print("knocked")
|
||||
body.knocked_timer.start()
|
||||
body.stunned_timer.start()
|
||||
body.velocity += blast_velocity
|
||||
if body is Enemy:
|
||||
body.stun()
|
||||
|
||||
@@ -23,7 +23,7 @@ var last_enemy : bool = false
|
||||
@export_group("Taunts")
|
||||
@export var taunts : Array[String] = []
|
||||
|
||||
|
||||
@onready var state_machine: Node = $StateMachine
|
||||
@onready var level_control = get_tree().current_scene
|
||||
@onready var movement_shape = $MovementShape
|
||||
@onready var barrel_1 = $TurretLook/Turret/Barrel1
|
||||
@@ -136,6 +136,8 @@ func spawn_casing():
|
||||
instance_casing.player_velocity = velocity * transform.basis
|
||||
get_tree().get_root().add_child(instance_casing)
|
||||
|
||||
func stun():
|
||||
state_machine.on_child_transition(state_machine.current_state,"stunned")
|
||||
|
||||
func save():
|
||||
var save_dict = {
|
||||
|
||||
Reference in New Issue
Block a user