atttack script starting to work

This commit is contained in:
derek
2025-04-30 16:35:45 -05:00
parent 4ca91fc7b5
commit ca4de10a5e
4 changed files with 35 additions and 3 deletions

View File

@@ -1094,7 +1094,7 @@ shape = SubResource("CylinderShape3D_gicen")
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
path_height_offset = 0.5
avoidance_enabled = true
radius = 1.0
radius = 1.5
[node name="Timers" type="Node" parent="."]

View File

@@ -1,2 +1,19 @@
extends EnemyState
class_name EnemyAttack
func Physics_Update(delta):
if enemy.is_player_visible():
#get player location
enemy.cache_player_pos()
#set player location as target
update_player_target()
#move and look at location
move_to_nav_point(delta)
turret_look2D(delta)
else:
Transitioned.emit(self,"idle") #when search is working make this search
func update_player_target():
move_target = enemy.player_last_seen
look_target = enemy.player_last_seen
enemy.nav_agent.set_target_position(move_target)

View File

@@ -13,6 +13,7 @@ func Enter():
get_new_wander_point()
func Update(delta):
attack_on_sight()
#on timeout change scan direction
if scan_timer > 0:
scan_timer -= delta

View File

@@ -31,9 +31,11 @@ func update_move_target():
func attack_on_sight():
if can_see:
if enemy.is_player_in_area() and enemy.is_player_visible():
enemy.cache_player_pos()
Transitioned.emit(self,"attack")
if enemy.turret_look.is_colliding():
if enemy.turret_look.get_collider() is Player:
enemy.cache_player_pos()
Transitioned.emit(self,"attack")
func search_on_lost_target():
@@ -63,6 +65,18 @@ func rotate_to_face2D(object,target,target_offset_angle,delta,turn_speed):
var direction = (pos2d - target_pos2d)
return lerp_angle(object.global_rotation.y,atan2(direction.x,direction.y) + deg_to_rad(target_offset_angle),delta * turn_speed)
func rotate_to_face3D(object,target,target_offset_angle,delta,turn_speed):
#to allow both nodes and positions to be passed to this function, test the target and use Vector3 coords
var target_transformed
if target == null:
target_transformed = object.global_position
elif target is Vector3:
target_transformed = target
elif target is Node3D:
target_transformed = target.global_position
func move_to_nav_point(delta):
var destination = enemy.nav_agent.get_next_path_position()
var local_destination = destination - enemy.global_position
@@ -75,8 +89,8 @@ func velocity_computed(safe_velocity):
enemy.velocity = enemy.velocity.move_toward(safe_velocity,.25)
func turret_look(target,delta):
enemy.turret_look.global_rotation.y = rotate_to_face2D(enemy.turret_look,target,0,delta,turret_speed)
func turret_look2D(delta):
enemy.turret_look.global_rotation.y = rotate_to_face2D(enemy.turret_look,look_target,0,delta,turret_speed)
func turret_scan_look(target,scan_direction,delta):