rudimentary search function. not working right yet

This commit is contained in:
Derek
2025-04-24 21:03:11 -05:00
parent 546f9a895e
commit 9306a3c562
6 changed files with 70 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=90 format=4 uid="uid://djr7vnr1hcx82"] [gd_scene load_steps=91 format=4 uid="uid://djr7vnr1hcx82"]
[ext_resource type="Script" uid="uid://cdofgtwevbray" path="res://scripts/spider.gd" id="1_7e7fe"] [ext_resource type="Script" uid="uid://cdofgtwevbray" path="res://scripts/spider.gd" id="1_7e7fe"]
[ext_resource type="PackedScene" uid="uid://h5ojldugfyyu" path="res://assets/bullet_enemy.tscn" id="2_aew5r"] [ext_resource type="PackedScene" uid="uid://h5ojldugfyyu" path="res://assets/bullet_enemy.tscn" id="2_aew5r"]
@@ -18,6 +18,7 @@
[ext_resource type="Texture2D" uid="uid://c7bdujukdjajv" path="res://assets/Models/SubstancePainterTest/spider-LOW_spider1.gunbarrel_Normal.png" id="10_wpql0"] [ext_resource type="Texture2D" uid="uid://c7bdujukdjajv" path="res://assets/Models/SubstancePainterTest/spider-LOW_spider1.gunbarrel_Normal.png" id="10_wpql0"]
[ext_resource type="Texture2D" uid="uid://d0w0lon4smlhm" path="res://assets/Models/SubstancePainterTest/spider-LOW_spider1.gunbarrel_Roughness.png" id="11_6mvds"] [ext_resource type="Texture2D" uid="uid://d0w0lon4smlhm" path="res://assets/Models/SubstancePainterTest/spider-LOW_spider1.gunbarrel_Roughness.png" id="11_6mvds"]
[ext_resource type="Script" uid="uid://dcnmjisrxf5iv" path="res://scripts/EnemyReload.gd" id="11_ekglj"] [ext_resource type="Script" uid="uid://dcnmjisrxf5iv" path="res://scripts/EnemyReload.gd" id="11_ekglj"]
[ext_resource type="Script" uid="uid://dvpf10vdnkfd" path="res://scripts/EnemySearch.gd" id="12_aasxo"]
[ext_resource type="Material" uid="uid://cc0el8wu0au85" path="res://assets/materials/OutlineMat.tres" id="13_ee4im"] [ext_resource type="Material" uid="uid://cc0el8wu0au85" path="res://assets/materials/OutlineMat.tres" id="13_ee4im"]
[ext_resource type="Texture2D" uid="uid://dn3b6uw8xr63m" path="res://assets/Textures/Smoke/smoketest_v1_0043.png" id="14_alcfd"] [ext_resource type="Texture2D" uid="uid://dn3b6uw8xr63m" path="res://assets/Textures/Smoke/smoketest_v1_0043.png" id="14_alcfd"]
[ext_resource type="Material" uid="uid://844q0haim4uh" path="res://assets/spider2_body.tres" id="14_gicen"] [ext_resource type="Material" uid="uid://844q0haim4uh" path="res://assets/spider2_body.tres" id="14_gicen"]
@@ -878,6 +879,10 @@ script = ExtResource("11_ekglj")
reload_sound = NodePath("../../AUIDO/Reload") reload_sound = NodePath("../../AUIDO/Reload")
enemy = NodePath("../..") enemy = NodePath("../..")
[node name="Search" type="Node" parent="StateMachine" node_paths=PackedStringArray("enemy")]
script = ExtResource("12_aasxo")
enemy = NodePath("../..")
[node name="VisibilityArea" type="Area3D" parent="."] [node name="VisibilityArea" type="Area3D" parent="."]
collision_layer = 0 collision_layer = 0
collision_mask = 4 collision_mask = 4

View File

@@ -25,6 +25,10 @@ func update_waypoint():
enemy.nav_agent.set_target_position(enemy.point_of_interest) enemy.nav_agent.set_target_position(enemy.point_of_interest)
func Update(delta): func Update(delta):
if enemy.point_of_interest != null:
if !enemy.is_player_visible():
Transitioned.emit(self,"search")
if heartbeat > 0: if heartbeat > 0:
heartbeat -= delta heartbeat -= delta
else: else:

58
scripts/EnemySearch.gd Normal file
View 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")

View File

@@ -0,0 +1 @@
uid://dvpf10vdnkfd

View File

@@ -20,7 +20,6 @@ func Update(delta):
if enemy.character_follow != null: if enemy.character_follow != null:
if can_see: if can_see:
if enemy.is_player_visible(): if enemy.is_player_visible():
print("PLAYER SPOTTED")
enemy.cache_player_pos() enemy.cache_player_pos()
Transitioned.emit(self,"attack") Transitioned.emit(self,"attack")

View File

@@ -37,3 +37,4 @@ func on_child_transition(state,new_state_name):
new_state.Enter() new_state.Enter()
current_state = new_state current_state = new_state
print("STATE CHANGED TO : ",current_state)