Tweaked turret AI

This commit is contained in:
Marco 2025-03-03 15:21:24 +01:00
commit a8c493c27a
4 changed files with 77 additions and 58 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=28 format=3 uid="uid://bjskkeb3ppcs8"]
[gd_scene load_steps=34 format=3 uid="uid://bjskkeb3ppcs8"]
[ext_resource type="Script" uid="uid://c2mo5hc1qb6kf" path="res://Scripts/Components/Actors/Actor.cs" id="1_g7c56"]
[ext_resource type="Texture2D" uid="uid://ke3ialixybfn" path="res://Sprites/Actors/Turret360.png" id="2_g7c56"]
@ -9,8 +9,11 @@
[ext_resource type="Script" uid="uid://c4qmuxjhheahr" path="res://Scripts/Components/ProximityPlayerDetection.cs" id="8_ktwe0"]
[ext_resource type="Script" uid="uid://cqwvssstkrdmw" path="res://Scripts/Components/Actors/ActorResourceProvider.cs" id="9_pyymf"]
[ext_resource type="PackedScene" uid="uid://cj63k0dmk7tl1" path="res://Scenes/Weapons/enemy_weapon_base.tscn" id="10_k6dxy"]
[ext_resource type="Resource" uid="uid://cdfmedtgp2rcn" path="res://Resources/Weapons/EnemyWeapon.tres" id="11_7jc33"]
[ext_resource type="PackedScene" uid="uid://dh81snen2f6bf" path="res://Scenes/Weapons/Bullets/enemyBullet_rice_blue_small.tscn" id="10_kuwnw"]
[ext_resource type="Script" uid="uid://b6h8slfcd5suh" path="res://Scripts/Resources/DecreasingSpeedModifier.cs" id="11_84800"]
[ext_resource type="Script" uid="uid://dslyrfcej3g2n" path="res://Scripts/Resources/BulletResource.cs" id="11_m663r"]
[ext_resource type="Script" uid="uid://2cijskgyt2xb" path="res://Scripts/Components/Actors/DamageReceiverActorModule.cs" id="12_04r4v"]
[ext_resource type="Script" uid="uid://b6fmrnipv88bk" path="res://Scripts/Resources/WeaponResource.cs" id="12_84800"]
[ext_resource type="Script" uid="uid://m0ag88kn0c40" path="res://Scripts/Components/Actors/DeathAnimationHandler.cs" id="13_ufa2c"]
[ext_resource type="Resource" uid="uid://dk2rbf88a5irh" path="res://Resources/Bullets/Explosion_Harmless.tres" id="14_jal4w"]
[ext_resource type="Script" uid="uid://b0qcrs74bdqhf" path="res://Scripts/Components/Actors/EnemyTurretRotationMovement.cs" id="15_g7c56"]
@ -86,6 +89,43 @@ radius = 5.0
[sub_resource type="CircleShape2D" id="CircleShape2D_sthwe"]
radius = 85.0529
[sub_resource type="Resource" id="Resource_ktwe0"]
script = ExtResource("11_84800")
decreaseRate = 0.1
metadata/_custom_type_script = "uid://b6h8slfcd5suh"
[sub_resource type="Resource" id="Resource_5eesc"]
script = ExtResource("11_m663r")
BulletScene = ExtResource("10_kuwnw")
BulletSpeed = 100.0
Direction = Vector2(1, 0)
BulletDamage = 40.0
LifeTime = 10.0
DestroyOnCollision = true
Owner = 2
DamageType = 0
Controllable = false
Modifier = SubResource("Resource_ktwe0")
TimeModifiers = Array[Object]([])
metadata/_custom_type_script = "uid://dslyrfcej3g2n"
[sub_resource type="Resource" id="Resource_hjdpo"]
script = ExtResource("12_84800")
Name = ""
BulletData = SubResource("Resource_5eesc")
RateOfFire = 0.4
BulletCapacity = 20
ReloadTime = 2.0
AutoReload = true
InfiniteAmmo = true
BulletsPerShot = 1
SpreadAngle = 0.0
RandomSpread = 0.0
ItemKey = ""
AmmoKey = ""
_rotationOffset = 0.0
metadata/_custom_type_script = "uid://b6fmrnipv88bk"
[sub_resource type="CircleShape2D" id="CircleShape2D_0tkae"]
radius = 5.09902
@ -93,8 +133,8 @@ radius = 5.09902
collision_layer = 16
collision_mask = 113
script = ExtResource("1_g7c56")
MovementSpeed = 30.0
Health = 6.0
MovementSpeed = 0.0
Health = 12.0
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_k6dxy")
@ -137,7 +177,7 @@ ResourceName = "Health"
MaxResource = 6.0
[node name="EnemyWeapon" parent="." instance=ExtResource("10_k6dxy")]
WeaponData = ExtResource("11_7jc33")
WeaponData = SubResource("Resource_hjdpo")
[node name="DamageReceiver" type="Node2D" parent="." node_paths=PackedStringArray("HealthProvider")]
script = ExtResource("12_04r4v")

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=122 format=4 uid="uid://bv451a8wgty4u"]
[gd_scene load_steps=118 format=4 uid="uid://bv451a8wgty4u"]
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
[ext_resource type="PackedScene" uid="uid://c4pr2707hbeph" path="res://Scenes/Actors/fsm_player.tscn" id="2_ksslq"]
@ -68,11 +68,9 @@
[ext_resource type="PackedScene" uid="uid://cd36ch65jijg0" path="res://Scenes/Activable/BulletEmitter.tscn" id="49_64oga"]
[ext_resource type="PackedScene" uid="uid://c5fiv1nioghfb" path="res://Scenes/Actors/Marisa.tscn" id="50_mp5ma"]
[ext_resource type="PackedScene" uid="uid://bqjcwxene73l2" path="res://Scenes/Actors/ActorEnemyTest.tscn" id="55_chha6"]
[ext_resource type="PackedScene" uid="uid://bjskkeb3ppcs8" path="res://Scenes/Actors/Turret360.tscn" id="62_h0jm4"]
[ext_resource type="Script" uid="uid://v57xjmhi28kw" path="res://Scripts/Resources/Events/ControlActorEvent.cs" id="64_rphi8"]
[ext_resource type="PackedScene" uid="uid://b0gpbkxdfbnjh" path="res://Scenes/Actors/ForceField_Horizontal.tscn" id="66_nxn3h"]
[ext_resource type="PackedScene" uid="uid://bi3f14klscvlw" path="res://Scenes/Weapons/Bullets/enemyBullet_mid_red.tscn" id="67_gmqhp"]
[ext_resource type="Script" uid="uid://b6h8slfcd5suh" path="res://Scripts/Resources/DecreasingSpeedModifier.cs" id="68_gmqhp"]
[ext_resource type="Script" uid="uid://dslyrfcej3g2n" path="res://Scripts/Resources/BulletResource.cs" id="69_jn1m0"]
[ext_resource type="PackedScene" uid="uid://cjsnhyl0nqbau" path="res://Scenes/Props/ICCTv.tscn" id="71_ji7au"]
[ext_resource type="PackedScene" uid="uid://cyy5i38sf7fid" path="res://Scenes/Props/Locker.tscn" id="72_fasrq"]
[ext_resource type="Resource" uid="uid://bj331rcsq65es" path="res://Resources/Bullets/EmitterTestBullet.tres" id="72_uit7r"]
@ -90,7 +88,7 @@ script = ExtResource("7_l32kg")
EggIndex = 0
StartingEquipment = Array[ExtResource("6_8tdlb")]([ExtResource("6_khabp")])
[sub_resource type="Shader" id="Shader_oy44o"]
[sub_resource type="Shader" id="Shader_ksslq"]
resource_local_to_scene = true
code = "shader_type canvas_item;
@ -114,9 +112,9 @@ void fragment() {
COLOR = color;
}"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_pniyx"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_jn1m0"]
resource_local_to_scene = true
shader = SubResource("Shader_oy44o")
shader = SubResource("Shader_ksslq")
shader_parameter/blink_color = Color(0, 0, 0, 1)
shader_parameter/blink_intensity = 0.0
shader_parameter/teleport_progress = 0.0
@ -155,6 +153,124 @@ source = 5
[sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_81ys3"]
input_name = "time"
[sub_resource type="VisualShader" id="VisualShader_usuub"]
resource_local_to_scene = true
code = "shader_type canvas_item;
render_mode blend_mix;
void fragment() {
vec4 n_out7p0;
// Texture2D:7
n_out7p0 = texture(TEXTURE, UV);
float n_out7p4 = n_out7p0.a;
// Input:2
vec2 n_out2p0 = UV;
// VectorDecompose:3
float n_out3p0 = n_out2p0.x;
float n_out3p1 = n_out2p0.y;
// FloatOp:4
float n_in4p1 = 100.00000;
float n_out4p0 = n_out3p1 * n_in4p1;
// Input:9
float n_out9p0 = TIME;
// FloatOp:10
float n_in10p1 = 5.00000;
float n_out10p0 = n_out9p0 * n_in10p1;
// FloatOp:11
float n_out11p0 = n_out4p0 + n_out10p0;
// FloatFunc:5
float n_out5p0 = sin(n_out11p0);
// Mix:8
float n_in8p2 = 0.50000;
float n_out8p0 = mix(n_out7p4, n_out5p0, n_in8p2);
// Output:0
COLOR.a = n_out8p0;
}
"
mode = 1
flags/light_only = false
nodes/fragment/0/position = Vector2(2520, 280)
nodes/fragment/2/node = SubResource("VisualShaderNodeInput_stwjs")
nodes/fragment/2/position = Vector2(60, 240)
nodes/fragment/3/node = SubResource("VisualShaderNodeVectorDecompose_kafk8")
nodes/fragment/3/position = Vector2(560, 280)
nodes/fragment/4/node = SubResource("VisualShaderNodeFloatOp_4ci11")
nodes/fragment/4/position = Vector2(880, 440)
nodes/fragment/5/node = SubResource("VisualShaderNodeFloatFunc_5vgt5")
nodes/fragment/5/position = Vector2(1760, 360)
nodes/fragment/6/node = SubResource("VisualShaderNodeInput_xwcy1")
nodes/fragment/6/position = Vector2(480, 1300)
nodes/fragment/7/node = SubResource("VisualShaderNodeTexture_c5icc")
nodes/fragment/7/position = Vector2(1200, 1160)
nodes/fragment/8/node = SubResource("VisualShaderNodeMix_6sm8i")
nodes/fragment/8/position = Vector2(2040, 860)
nodes/fragment/9/node = SubResource("VisualShaderNodeInput_81ys3")
nodes/fragment/9/position = Vector2(300, 660)
nodes/fragment/10/node = SubResource("VisualShaderNodeFloatOp_7rr75")
nodes/fragment/10/position = Vector2(880, 800)
nodes/fragment/11/node = SubResource("VisualShaderNodeFloatOp_own43")
nodes/fragment/11/position = Vector2(1360, 480)
nodes/fragment/connections = PackedInt32Array(2, 0, 3, 0, 3, 1, 4, 0, 6, 0, 7, 2, 7, 4, 8, 0, 5, 0, 8, 1, 8, 0, 0, 1, 9, 0, 10, 0, 4, 0, 11, 0, 10, 0, 11, 1, 11, 0, 5, 0)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_h0jm4"]
resource_local_to_scene = true
shader = SubResource("VisualShader_usuub")
[sub_resource type="Shader" id="Shader_oy44o"]
resource_local_to_scene = true
code = "shader_type canvas_item;
uniform vec4 blink_color: source_color;
uniform float blink_intensity = 0.0;
uniform float teleport_progress = 0.0; // 0 = fully visible, 1 = fully gone
uniform float scanline_density = 50.0; // Controls the number of scanlines
void fragment() {
vec4 color = texture(TEXTURE, UV);
color = mix(color, blink_color, blink_intensity * color.a);
// Generate scanline effect based on teleport_progress
float scanline = mod(UV.y * scanline_density, 1.0); // Creates scanline pattern
float cutoff = smoothstep(0.0, 1.0, UV.y - teleport_progress); // Controls disappearance
// Mix scanline effect with cutoff to make it gradually disappear
float alpha_multiplier = step(scanline, cutoff);
color.a *= alpha_multiplier;
COLOR = color;
}"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_pniyx"]
resource_local_to_scene = true
shader = SubResource("Shader_oy44o")
shader_parameter/blink_color = Color(0, 0, 0, 1)
shader_parameter/blink_intensity = 0.0
shader_parameter/teleport_progress = 0.0
shader_parameter/scanline_density = 50.0
[sub_resource type="VisualShader" id="VisualShader_5ews6"]
resource_local_to_scene = true
code = "shader_type canvas_item;
@ -241,124 +357,6 @@ nodes/fragment/connections = PackedInt32Array(2, 0, 3, 0, 3, 1, 4, 0, 6, 0, 7, 2
resource_local_to_scene = true
shader = SubResource("VisualShader_5ews6")
[sub_resource type="Shader" id="Shader_xof4a"]
resource_local_to_scene = true
code = "shader_type canvas_item;
uniform vec4 blink_color: source_color;
uniform float blink_intensity = 0.0;
uniform float teleport_progress = 0.0; // 0 = fully visible, 1 = fully gone
uniform float scanline_density = 50.0; // Controls the number of scanlines
void fragment() {
vec4 color = texture(TEXTURE, UV);
color = mix(color, blink_color, blink_intensity * color.a);
// Generate scanline effect based on teleport_progress
float scanline = mod(UV.y * scanline_density, 1.0); // Creates scanline pattern
float cutoff = smoothstep(0.0, 1.0, UV.y - teleport_progress); // Controls disappearance
// Mix scanline effect with cutoff to make it gradually disappear
float alpha_multiplier = step(scanline, cutoff);
color.a *= alpha_multiplier;
COLOR = color;
}"
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ati1v"]
resource_local_to_scene = true
shader = SubResource("Shader_xof4a")
shader_parameter/blink_color = Color(0, 0, 0, 1)
shader_parameter/blink_intensity = 0.0
shader_parameter/teleport_progress = 0.0
shader_parameter/scanline_density = 50.0
[sub_resource type="VisualShader" id="VisualShader_ma1ta"]
resource_local_to_scene = true
code = "shader_type canvas_item;
render_mode blend_mix;
void fragment() {
vec4 n_out7p0;
// Texture2D:7
n_out7p0 = texture(TEXTURE, UV);
float n_out7p4 = n_out7p0.a;
// Input:2
vec2 n_out2p0 = UV;
// VectorDecompose:3
float n_out3p0 = n_out2p0.x;
float n_out3p1 = n_out2p0.y;
// FloatOp:4
float n_in4p1 = 100.00000;
float n_out4p0 = n_out3p1 * n_in4p1;
// Input:9
float n_out9p0 = TIME;
// FloatOp:10
float n_in10p1 = 5.00000;
float n_out10p0 = n_out9p0 * n_in10p1;
// FloatOp:11
float n_out11p0 = n_out4p0 + n_out10p0;
// FloatFunc:5
float n_out5p0 = sin(n_out11p0);
// Mix:8
float n_in8p2 = 0.50000;
float n_out8p0 = mix(n_out7p4, n_out5p0, n_in8p2);
// Output:0
COLOR.a = n_out8p0;
}
"
mode = 1
flags/light_only = false
nodes/fragment/0/position = Vector2(2520, 280)
nodes/fragment/2/node = SubResource("VisualShaderNodeInput_stwjs")
nodes/fragment/2/position = Vector2(60, 240)
nodes/fragment/3/node = SubResource("VisualShaderNodeVectorDecompose_kafk8")
nodes/fragment/3/position = Vector2(560, 280)
nodes/fragment/4/node = SubResource("VisualShaderNodeFloatOp_4ci11")
nodes/fragment/4/position = Vector2(880, 440)
nodes/fragment/5/node = SubResource("VisualShaderNodeFloatFunc_5vgt5")
nodes/fragment/5/position = Vector2(1760, 360)
nodes/fragment/6/node = SubResource("VisualShaderNodeInput_xwcy1")
nodes/fragment/6/position = Vector2(480, 1300)
nodes/fragment/7/node = SubResource("VisualShaderNodeTexture_c5icc")
nodes/fragment/7/position = Vector2(1200, 1160)
nodes/fragment/8/node = SubResource("VisualShaderNodeMix_6sm8i")
nodes/fragment/8/position = Vector2(2040, 860)
nodes/fragment/9/node = SubResource("VisualShaderNodeInput_81ys3")
nodes/fragment/9/position = Vector2(300, 660)
nodes/fragment/10/node = SubResource("VisualShaderNodeFloatOp_7rr75")
nodes/fragment/10/position = Vector2(880, 800)
nodes/fragment/11/node = SubResource("VisualShaderNodeFloatOp_own43")
nodes/fragment/11/position = Vector2(1360, 480)
nodes/fragment/connections = PackedInt32Array(2, 0, 3, 0, 3, 1, 4, 0, 6, 0, 7, 2, 7, 4, 8, 0, 5, 0, 8, 1, 8, 0, 0, 1, 9, 0, 10, 0, 4, 0, 11, 0, 10, 0, 11, 1, 11, 0, 5, 0)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_bwt6v"]
resource_local_to_scene = true
shader = SubResource("VisualShader_ma1ta")
[sub_resource type="Resource" id="Resource_hppa0"]
script = ExtResource("40_7qam0")
WaitForCompletion = true
@ -442,32 +440,12 @@ ActivationType = 0
Targets = Array[NodePath]([NodePath("../Rumia")])
WaitForCompletion = true
[sub_resource type="Resource" id="Resource_gd7x4"]
[sub_resource type="Resource" id="Resource_xof4a"]
resource_local_to_scene = true
script = ExtResource("49_0si7g")
Target = NodePath(".")
WaitForCompletion = true
[sub_resource type="Resource" id="Resource_ksslq"]
script = ExtResource("68_gmqhp")
decreaseRate = 4.0
metadata/_custom_type_script = "uid://b6h8slfcd5suh"
[sub_resource type="Resource" id="Resource_oy44o"]
script = ExtResource("69_jn1m0")
BulletScene = ExtResource("67_gmqhp")
BulletSpeed = 80.0
Direction = Vector2(1, 0)
BulletDamage = 20.0
LifeTime = 20.0
DestroyOnCollision = true
Owner = 2
DamageType = 0
Controllable = false
Modifier = SubResource("Resource_ksslq")
TimeModifiers = Array[Object]([])
metadata/_custom_type_script = "uid://dslyrfcej3g2n"
[node name="GameScene" type="Node2D"]
process_mode = 3
script = ExtResource("1_8tmoj")
@ -621,13 +599,13 @@ position = Vector2(-779, -550)
[node name="HorizontalForceField" parent="Factory Tilemaps/Debug Room" instance=ExtResource("66_nxn3h")]
position = Vector2(-749, -496)
TurnOffMaterial = SubResource("ShaderMaterial_pniyx")
ActiveMaterial = SubResource("ShaderMaterial_pqe7f")
TurnOffMaterial = SubResource("ShaderMaterial_jn1m0")
ActiveMaterial = SubResource("ShaderMaterial_h0jm4")
[node name="HorizontalForceField2" parent="Factory Tilemaps/Debug Room" instance=ExtResource("66_nxn3h")]
position = Vector2(-735, -532)
TurnOffMaterial = SubResource("ShaderMaterial_ati1v")
ActiveMaterial = SubResource("ShaderMaterial_bwt6v")
TurnOffMaterial = SubResource("ShaderMaterial_pniyx")
ActiveMaterial = SubResource("ShaderMaterial_pqe7f")
[node name="ControllabeFairyGuard" parent="Factory Tilemaps/Debug Room" instance=ExtResource("73_ier4h")]
position = Vector2(-581, -346)
@ -1022,7 +1000,7 @@ Events = Array[Object]([SubResource("Resource_068l7"), SubResource("Resource_l3n
[node name="BossBattleStartScript" parent="Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
position = Vector2(-1487, -396)
Events = Array[Object]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_gd7x4")])
Events = Array[Object]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_xof4a")])
[node name="Enemy13" parent="Factory Tilemaps/LevelProps" instance=ExtResource("47_u1ve6")]
position = Vector2(-1657, -788)
@ -1035,13 +1013,6 @@ Target = NodePath("../BulletEmitter")
position = Vector2(-724, 56)
BulletResource = ExtResource("72_uit7r")
[node name="BulletEmitter2" parent="Factory Tilemaps/LevelProps" instance=ExtResource("49_64oga")]
position = Vector2(-1149, -630)
BulletResource = SubResource("Resource_oy44o")
Spread = 360.0
Count = 8
EmissionRotation = 20.0
[node name="StartPosition" type="Marker2D" parent="Factory Tilemaps/LevelProps"]
position = Vector2(-808, -171)
@ -1165,6 +1136,9 @@ position = Vector2(-1220, -402)
[node name="Fairy10" parent="Factory Tilemaps/LevelProps" instance=ExtResource("73_s4x1s")]
position = Vector2(-1080, -399)
[node name="Turret360" parent="Factory Tilemaps/LevelProps" instance=ExtResource("62_h0jm4")]
position = Vector2(-1157, -628)
[node name="Ammo1" parent="Factory Tilemaps" instance=ExtResource("34_17pjh")]
position = Vector2(-872, -220)

View file

@ -60,10 +60,9 @@ public partial class EnemyTurretRotationMovement : MovementHandler
switch (_actorAi.State)
{
case EnemyState.Idle:
if (_playerDetection != null && IsPlayerInSight)
if (_playerDetection != null && IsPlayerInRange && IsPlayerInSight)
{
_actorAi.State = EnemyState.Alert;
GD.Print("Switching to alert");
}
break;
@ -75,10 +74,14 @@ public partial class EnemyTurretRotationMovement : MovementHandler
_lastPlayerPosition = _playerDetection.CachedPlayer.GlobalPosition;
}
if (IsPlayerInSight)
if (IsPlayerInRange && IsPlayerInSight)
{
Shoot();
}
else
{
_actorAi.State = EnemyState.Idle;
}
break;
}
}

View file

@ -1,4 +1,6 @@
namespace Cirno.Scripts.Resources;
using Godot;
namespace Cirno.Scripts.Resources;
public interface IBulletModifier
{