very happy with idle script now
This commit is contained in:
@@ -17,8 +17,8 @@
|
|||||||
size = Vector3(92.25, 82.386, 76.6396)
|
size = Vector3(92.25, 82.386, 76.6396)
|
||||||
|
|
||||||
[sub_resource type="NavigationMesh" id="NavigationMesh_wa46b"]
|
[sub_resource type="NavigationMesh" id="NavigationMesh_wa46b"]
|
||||||
vertices = PackedVector3Array(-19.5, 1, 0, -5, 1, 0, -4.75, 1, -1.5, -2.75, 1, -19.5, -19.5, 1, -19.5, -2.75, 1, -1.5, 2.75, 1, -1.5, 3, 1, -19.5, 5.75, 1, -1.25, 19.5, 1, -1.5, 19.5, 1, -19.5, 6.25, 1, 11.25, 4.75, 1, 11.5, 4.75, 1, 19.5, 19.5, 1, 19.5, 6.25, 1, -1, -4, 4.5, -0.5, -4, 4.5, 0.5, 3, 4.5, 0.5, 3, 4.5, -0.5, -3.75, 1, -0.25, -3.75, 1, 0.25, 3, 1, 0.25, 3, 1, -0.25, 4, 5, -0.25, 4, 5, 10.5, 5.25, 5, 10.5, 5.25, 5, -0.25, -19.5, 1, 12, -8.75, 1, 12, -8.5, 1, 11.25, -5, 1, 1, -6, 1, 10.75, -4.5, 1, 1.5, 4.25, 1, 1.5, 4.25, 1, 10.25, 5, 1, 10.25, 5, 1, 1.25, 3, 1, 10.75, 3, 1, 1.5, -8.25, 1, 12.25, -8.5, 1, 18.25, -9.5, 1, 18.5, -9.5, 1, 19.5, 3.25, 1, 11.5, -10, 4, 13.25, -9.75, 4, 17.5, -9.25, 4, 13.5, -9.25, 4, 13, -19.5, 4, 13, -10.75, 1, 18.25, -19.5, 1, 19.5, -10.75, 1, 14.25, -19.5, 1, 14.25)
|
vertices = PackedVector3Array(-19.5, 1, 0, -5, 1, 0, -5, 1, -1.25, -4.5, 1, -1.5, -4.5, 1, -19.5, -19.5, 1, -19.5, 8.5, 1, -1.5, 8.75, 1, -19.5, 9, 1, 0.5, 19.5, 1, 0.5, 19.5, 1, -19.5, -4, 4.5, -0.5, -4, 4.5, 0.5, 3, 4.5, 0.5, 3, 4.5, -0.5, 7.25, 4.25, -0.5, 7.25, 4.25, 0.25, 7.75, 4.25, 0.25, 7.75, 4.25, -0.5, -3.75, 1, -0.25, -3.75, 1, 0.25, 3, 1, 0.25, 3, 1, -0.25, 4, 5, -0.25, 4, 5, 10.5, 5.25, 5, 10.5, 5.25, 5, -0.25, -19.5, 1, 12, -8.75, 1, 12, -8.5, 1, 11.25, -5, 1, 1, 6.25, 1, 11.25, 4.75, 1, 11.5, 4.75, 1, 19.5, 8.75, 1, 1.25, 6.25, 1, 1.25, 19.5, 1, 19.5, -6, 1, 10.75, -4.5, 1, 1.5, 4.25, 1, 1.5, 4.25, 1, 10.25, 5, 1, 10.25, 5, 1, 1.25, 3, 1, 10.75, 3, 1, 1.5, -8.25, 1, 12.25, -8.5, 1, 18.25, -9.5, 1, 18.5, -9.5, 1, 19.5, 3.25, 1, 11.5, -10, 4, 13.25, -9.75, 4, 17.5, -9.25, 4, 13.5, -9.25, 4, 13, -19.5, 4, 13, -10.75, 1, 18.25, -19.5, 1, 19.5, -10.75, 1, 14.25, -19.5, 1, 14.25)
|
||||||
polygons = [PackedInt32Array(1, 0, 2), PackedInt32Array(2, 0, 4), PackedInt32Array(2, 4, 3), PackedInt32Array(3, 5, 2), PackedInt32Array(5, 3, 6), PackedInt32Array(6, 3, 7), PackedInt32Array(8, 6, 9), PackedInt32Array(9, 6, 7), PackedInt32Array(9, 7, 10), PackedInt32Array(12, 11, 13), PackedInt32Array(13, 11, 14), PackedInt32Array(15, 8, 9), PackedInt32Array(15, 9, 11), PackedInt32Array(11, 9, 14), PackedInt32Array(19, 18, 16), PackedInt32Array(16, 18, 17), PackedInt32Array(23, 22, 20), PackedInt32Array(20, 22, 21), PackedInt32Array(27, 26, 24), PackedInt32Array(24, 26, 25), PackedInt32Array(30, 29, 28), PackedInt32Array(31, 30, 1), PackedInt32Array(1, 30, 28), PackedInt32Array(1, 28, 0), PackedInt32Array(33, 32, 31), PackedInt32Array(31, 32, 30), PackedInt32Array(35, 34, 36), PackedInt32Array(36, 34, 37), PackedInt32Array(39, 38, 33), PackedInt32Array(33, 38, 32), PackedInt32Array(29, 30, 40), PackedInt32Array(40, 30, 32), PackedInt32Array(42, 41, 43), PackedInt32Array(43, 41, 13), PackedInt32Array(44, 12, 13), PackedInt32Array(40, 32, 41), PackedInt32Array(41, 32, 38), PackedInt32Array(41, 38, 44), PackedInt32Array(41, 44, 13), PackedInt32Array(48, 47, 45), PackedInt32Array(45, 47, 46), PackedInt32Array(48, 45, 49), PackedInt32Array(42, 43, 50), PackedInt32Array(50, 43, 51), PackedInt32Array(52, 50, 53), PackedInt32Array(53, 50, 51)]
|
polygons = [PackedInt32Array(2, 1, 0), PackedInt32Array(2, 0, 3), PackedInt32Array(3, 0, 4), PackedInt32Array(4, 0, 5), PackedInt32Array(3, 4, 6), PackedInt32Array(6, 4, 7), PackedInt32Array(8, 6, 9), PackedInt32Array(9, 6, 7), PackedInt32Array(9, 7, 10), PackedInt32Array(14, 13, 11), PackedInt32Array(11, 13, 12), PackedInt32Array(18, 17, 15), PackedInt32Array(15, 17, 16), PackedInt32Array(22, 21, 19), PackedInt32Array(19, 21, 20), PackedInt32Array(26, 25, 23), PackedInt32Array(23, 25, 24), PackedInt32Array(29, 28, 27), PackedInt32Array(30, 29, 1), PackedInt32Array(1, 29, 27), PackedInt32Array(1, 27, 0), PackedInt32Array(33, 32, 31), PackedInt32Array(31, 35, 34), PackedInt32Array(8, 9, 34), PackedInt32Array(34, 9, 31), PackedInt32Array(31, 9, 33), PackedInt32Array(33, 9, 36), PackedInt32Array(38, 37, 30), PackedInt32Array(30, 37, 29), PackedInt32Array(40, 39, 41), PackedInt32Array(41, 39, 42), PackedInt32Array(44, 43, 38), PackedInt32Array(38, 43, 37), PackedInt32Array(28, 29, 45), PackedInt32Array(45, 29, 37), PackedInt32Array(47, 46, 48), PackedInt32Array(48, 46, 33), PackedInt32Array(49, 32, 33), PackedInt32Array(45, 37, 46), PackedInt32Array(46, 37, 43), PackedInt32Array(46, 43, 49), PackedInt32Array(46, 49, 33), PackedInt32Array(53, 52, 50), PackedInt32Array(50, 52, 51), PackedInt32Array(53, 50, 54), PackedInt32Array(47, 48, 55), PackedInt32Array(55, 48, 56), PackedInt32Array(57, 55, 58), PackedInt32Array(58, 55, 56)]
|
||||||
|
|
||||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_t6ubg"]
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_t6ubg"]
|
||||||
transparency = 1
|
transparency = 1
|
||||||
@@ -81,6 +81,11 @@ use_collision = true
|
|||||||
size = Vector3(5.10229, 4.0282, 1)
|
size = Vector3(5.10229, 4.0282, 1)
|
||||||
material = SubResource("StandardMaterial3D_sdike")
|
material = SubResource("StandardMaterial3D_sdike")
|
||||||
|
|
||||||
|
[node name="vendingmachine" parent="NavigationRegion3D" instance=ExtResource("11_sdike")]
|
||||||
|
transform = Transform3D(-0.206085, 0, 0.978534, 0, 1, 0, -0.978534, 0, -0.206085, 6.89547, 0.711414, 0.072493)
|
||||||
|
item = ExtResource("12_5u3xe")
|
||||||
|
is_pickup = true
|
||||||
|
|
||||||
[node name="Level" type="Node3D" parent="."]
|
[node name="Level" type="Node3D" parent="."]
|
||||||
script = ExtResource("5_sdike")
|
script = ExtResource("5_sdike")
|
||||||
start_enemies = 1
|
start_enemies = 1
|
||||||
@@ -90,8 +95,3 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.28023, 1.45981, -1.07754)
|
|||||||
|
|
||||||
[node name="EnemySpawner" parent="Level" instance=ExtResource("6_5u3xe")]
|
[node name="EnemySpawner" parent="Level" instance=ExtResource("6_5u3xe")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.291284, 1, 3.32874)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.291284, 1, 3.32874)
|
||||||
|
|
||||||
[node name="vendingmachine" parent="." instance=ExtResource("11_sdike")]
|
|
||||||
transform = Transform3D(-0.206085, 0, 0.978534, 0, 1, 0, -0.978534, 0, -0.206085, 6.89547, 0.711414, 0.072493)
|
|
||||||
item = ExtResource("12_5u3xe")
|
|
||||||
is_pickup = true
|
|
||||||
|
|||||||
@@ -872,6 +872,7 @@ initial_state = NodePath("Idle")
|
|||||||
script = ExtResource("7_cwyr0")
|
script = ExtResource("7_cwyr0")
|
||||||
enemy = NodePath("../..")
|
enemy = NodePath("../..")
|
||||||
move_speed = 1.5
|
move_speed = 1.5
|
||||||
|
turret_speed = 0.5
|
||||||
|
|
||||||
[node name="Stunned" type="Node" parent="StateMachine" node_paths=PackedStringArray("enemy")]
|
[node name="Stunned" type="Node" parent="StateMachine" node_paths=PackedStringArray("enemy")]
|
||||||
script = ExtResource("8_wpql0")
|
script = ExtResource("8_wpql0")
|
||||||
@@ -968,11 +969,6 @@ draw_pass_1 = SubResource("PlaneMesh_eqd73")
|
|||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00161432, 0.000886798, -0.0469466)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00161432, 0.000886798, -0.0469466)
|
||||||
shape = SubResource("ConcavePolygonShape3D_kddmj")
|
shape = SubResource("ConcavePolygonShape3D_kddmj")
|
||||||
|
|
||||||
[node name="TurretLookNext" type="RayCast3D" parent="."]
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00161432, 1.62046, 0.00134204)
|
|
||||||
target_position = Vector3(0, 0, -50)
|
|
||||||
collision_mask = 5
|
|
||||||
|
|
||||||
[node name="LineOfSight" type="RayCast3D" parent="."]
|
[node name="LineOfSight" type="RayCast3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00161432, 1.62046, 0.00134204)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00161432, 1.62046, 0.00134204)
|
||||||
top_level = true
|
top_level = true
|
||||||
|
|||||||
@@ -1,37 +1,40 @@
|
|||||||
extends EnemyState
|
extends EnemyState
|
||||||
class_name EnemyIdle
|
class_name EnemyIdle
|
||||||
|
|
||||||
@export var idle_time_range : Vector2 = Vector2(5,7)
|
@export var wander_distance_max : float = 15.0
|
||||||
@export var wander_distance_max : float = 30.0
|
@export var scan_cone_angle : float = 90
|
||||||
|
@export var scan_time : float = 3
|
||||||
|
|
||||||
var idle_timer
|
var idle_timer
|
||||||
|
var scan_timer
|
||||||
|
var scan_direction
|
||||||
|
|
||||||
func Enter():
|
func Enter():
|
||||||
idle_timer = randf_range(idle_time_range.x,idle_time_range.y)
|
scan_direction = scan_cone_angle/2
|
||||||
|
scan_timer = scan_time
|
||||||
get_new_wander_point()
|
get_new_wander_point()
|
||||||
|
|
||||||
func Update(delta):
|
func Update(delta):
|
||||||
#attack_on_sight()
|
if scan_timer > 0:
|
||||||
if idle_timer > 0:
|
scan_timer -= delta
|
||||||
idle_timer -= delta
|
|
||||||
else:
|
else:
|
||||||
get_new_wander_point()
|
change_scan_direction()
|
||||||
|
|
||||||
|
func Physics_Update(delta):
|
||||||
debug_marker(move_target)
|
debug_marker(move_target)
|
||||||
move_to_nav_point(delta)
|
if enemy.nav_agent.is_navigation_finished():
|
||||||
#turret_look(delta)
|
get_new_wander_point()
|
||||||
|
else:
|
||||||
|
move_to_nav_point(delta)
|
||||||
|
turret_scan_look(enemy.nav_agent.get_next_path_position(),scan_direction,delta)
|
||||||
|
|
||||||
func get_new_wander_point():
|
func get_new_wander_point():
|
||||||
#reset timer
|
#reset timer
|
||||||
idle_timer = randf_range(idle_time_range.x,idle_time_range.y)
|
|
||||||
var x = randf_range(-wander_distance_max,wander_distance_max)
|
var x = randf_range(-wander_distance_max,wander_distance_max)
|
||||||
var z = randf_range(-wander_distance_max,wander_distance_max)
|
var z = randf_range(-wander_distance_max,wander_distance_max)
|
||||||
move_target = enemy.global_position + Vector3(x,0,z)
|
move_target = enemy.global_position + Vector3(x,0,z)
|
||||||
enemy.nav_agent.set_target_position(move_target)
|
enemy.nav_agent.set_target_position(move_target)
|
||||||
|
|
||||||
print("MOVE TARGET : ",move_target)
|
func change_scan_direction():
|
||||||
|
scan_timer = scan_time
|
||||||
get_turret_look_destination()
|
scan_direction = -scan_direction
|
||||||
|
|
||||||
func get_turret_look_destination():
|
|
||||||
look_target = move_target + Vector3(0,3,0)
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func search_for_suspicious_sounds():
|
|||||||
enemy.player_last_seen = null
|
enemy.player_last_seen = null
|
||||||
Transitioned.emit(self,"search")
|
Transitioned.emit(self,"search")
|
||||||
|
|
||||||
func rotate_to_face2D(object,target,delta,turn_speed):
|
func rotate_to_face2D(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
|
#to allow both nodes and positions to be passed to this function, test the target and use Vector3 coords
|
||||||
var target_transformed
|
var target_transformed
|
||||||
if target == null:
|
if target == null:
|
||||||
@@ -61,21 +61,22 @@ func rotate_to_face2D(object,target,delta,turn_speed):
|
|||||||
var pos2d = Vector2(object.global_position.x,object.global_position.z)
|
var pos2d = Vector2(object.global_position.x,object.global_position.z)
|
||||||
var target_pos2d = Vector2(target_transformed.x,target_transformed.z)
|
var target_pos2d = Vector2(target_transformed.x,target_transformed.z)
|
||||||
var direction = (pos2d - target_pos2d)
|
var direction = (pos2d - target_pos2d)
|
||||||
return lerp_angle(object.rotation.y,atan2(direction.x,direction.y),delta * turn_speed)
|
return lerp_angle(object.global_rotation.y,atan2(direction.x,direction.y) + deg_to_rad(target_offset_angle),delta * turn_speed)
|
||||||
|
|
||||||
func clear_point_of_interest():
|
|
||||||
enemy.point_of_interest = null
|
|
||||||
|
|
||||||
func move_to_nav_point(delta):
|
func move_to_nav_point(delta):
|
||||||
var destination = enemy.nav_agent.get_next_path_position()
|
var destination = enemy.nav_agent.get_next_path_position()
|
||||||
var local_destination = destination - enemy.global_position
|
var local_destination = destination - enemy.global_position
|
||||||
var direction = local_destination.normalized()
|
var direction = local_destination.normalized()
|
||||||
if enemy.global_position.distance_to(destination) > 1:
|
enemy.velocity = direction * move_speed
|
||||||
enemy.velocity = direction * move_speed
|
enemy.global_rotation.y = rotate_to_face2D(enemy,destination,0,delta,body_turn_speed)
|
||||||
enemy.global_rotation.y = rotate_to_face2D(enemy,destination,delta,body_turn_speed)
|
|
||||||
|
func turret_look(target,delta):
|
||||||
|
enemy.turret_look.global_rotation.y = rotate_to_face2D(enemy.turret_look,target,0,delta,turret_speed)
|
||||||
|
|
||||||
|
|
||||||
|
func turret_scan_look(target,scan_direction,delta):
|
||||||
|
enemy.turret_look.global_rotation.y = rotate_to_face2D(enemy.turret_look,target,scan_direction,delta,turret_speed)
|
||||||
|
|
||||||
func turret_look(delta):
|
|
||||||
enemy.turret_look.global_rotation.y = rotate_to_face2D(enemy.turret_look,move_target,delta,50)
|
|
||||||
|
|
||||||
func debug_marker(target_pos):
|
func debug_marker(target_pos):
|
||||||
if enemy.debug_tools:
|
if enemy.debug_tools:
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ var last_enemy : bool = false
|
|||||||
@onready var postfire_timer = $Timers/postfire_timer
|
@onready var postfire_timer = $Timers/postfire_timer
|
||||||
@onready var knocked_timer = $Timers/knocked_timer
|
@onready var knocked_timer = $Timers/knocked_timer
|
||||||
@onready var stunned_timer = $Timers/stunned_timer
|
@onready var stunned_timer = $Timers/stunned_timer
|
||||||
@onready var turret_look_next = $TurretLookNext
|
|
||||||
@onready var body = $body
|
@onready var body = $body
|
||||||
@onready var audio_fire = $AUIDO/Fire
|
@onready var audio_fire = $AUIDO/Fire
|
||||||
@onready var turret = $TurretLook/Turret
|
@onready var turret = $TurretLook/Turret
|
||||||
|
|||||||
Reference in New Issue
Block a user