diff --git a/Characters/Weeb.tscn b/Characters/Weeb.tscn index bf22069..e69967b 100644 --- a/Characters/Weeb.tscn +++ b/Characters/Weeb.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=37 format=3 uid="uid://glh1bi8fq0y3"] +[gd_scene load_steps=38 format=3 uid="uid://glh1bi8fq0y3"] [ext_resource type="Script" path="res://Characters/NPC.cs" id="1_7fqw6"] [ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="1_alo0e"] @@ -14,6 +14,7 @@ [ext_resource type="AnimationLibrary" uid="uid://xs6g84fkepjr" path="res://Assets/Animations/npc_hurt.res" id="8_3yuxr"] [ext_resource type="Script" path="res://Utils/AnimationManager.cs" id="8_dh32x"] [ext_resource type="Material" uid="uid://bat28samf7ukd" path="res://Assets/Sprites/Particles/NPCDamageProcessMaterial.tres" id="8_t3yoe"] +[ext_resource type="Script" path="res://State/Thinker/PursueState.cs" id="8_vu75d"] [ext_resource type="AnimationLibrary" uid="uid://f1aqhnxndybx" path="res://Assets/Animations/npc_stun.res" id="9_bpu34"] [ext_resource type="Texture2D" uid="uid://bd8l8kafb42dt" path="res://Assets/Sprites/Particles/circle.png" id="9_g45p5"] [ext_resource type="Material" uid="uid://2tsvsp45elru" path="res://Assets/Sprites/Particles/NPCDeathParticles.tres" id="10_8f2hb"] @@ -201,9 +202,18 @@ PassiveState = NodePath("../Idle") PursueState = NodePath("../Idle") NPC = NodePath("../..") +[node name="Pursue" type="Node" parent="ThinkerStateMachine" node_paths=PackedStringArray("NavigationAgent", "AttackState", "PassiveState", "NPC")] +script = ExtResource("8_vu75d") +NavigationAgent = NodePath("../../NavigationAgent2D") +AttackState = NodePath("../Attack") +PassiveState = NodePath("../Idle") +MinDistanceToTarget = 64.0 +MaxDistanceFromOrigin = 256.0 +NPC = NodePath("../..") + [node name="Idle" type="Node" parent="ThinkerStateMachine" node_paths=PackedStringArray("PursueState", "NavigationAgent", "NPC")] script = ExtResource("7_w5q4u") -PursueState = NodePath("../Attack") +PursueState = NodePath("../Pursue") MinTargetDistance = 24.0 PursueOnLineOfSight = true MinLineOfSightDistance = 256.0 diff --git a/State/Thinker/AttackState.cs b/State/Thinker/AttackState.cs index e34fe3a..7f56572 100644 --- a/State/Thinker/AttackState.cs +++ b/State/Thinker/AttackState.cs @@ -41,7 +41,7 @@ public partial class AttackState : ThinkerState public ThinkerState PursueState { get; set; } [Export] - public bool PursueOnLineOfSight { get; set; } = true; + public bool PursueOnNoLOS { get; set; } = true; protected Characters.Character _bestTarget; @@ -175,12 +175,14 @@ public partial class AttackState : ThinkerState return PursueState; } - if (PursueOnLineOfSight && !NPC.HasLineOfSight(bestTarget)) + if (PursueOnNoLOS && !NPC.HasLineOfSight(bestTarget)) { return PursueState; } } + NPC.LastSeenPosition = bestTarget.GlobalPosition; + UpdateWeights(pos); if (dist <= UseItemDistance && NPC.CanAttack) diff --git a/State/Thinker/PursueState.cs b/State/Thinker/PursueState.cs index ceb8129..431a3fb 100644 --- a/State/Thinker/PursueState.cs +++ b/State/Thinker/PursueState.cs @@ -28,7 +28,7 @@ public partial class PursueState : ThinkerState public override ThinkerState Think() { var bestTarget = NPC.FindBestTarget(); - if (bestTarget is not null) + if (bestTarget is not null && NPC.HasLineOfSight(bestTarget)) { // navigate towards the best target var pos = bestTarget.GlobalPosition; @@ -36,18 +36,16 @@ public partial class PursueState : ThinkerState NPC.Target = NPC.GlobalPosition.DirectionTo(pos); NPC.LastSeenPosition = pos; - if (NPC.HasLineOfSight(bestTarget)) + if (NPC.GlobalPosition.DistanceTo(pos) < MinDistanceToTarget) { - if (NPC.GlobalPosition.DistanceTo(pos) < MinDistanceToTarget) - { - return AttackState; - } + return AttackState; } } else { // go to last seen position of last best target NavigationAgent.TargetPosition = NPC.LastSeenPosition; + GD.Print(NPC.LastSeenPosition); } return null; }