Skip to content

Commit

Permalink
Merge pull request #25 from Abb4/fixing-#20-by-removing-circular-refe…
Browse files Browse the repository at this point in the history
…rence

removed `NavigateTowards2dNodes` attribute, instead push parent values downwards by searching appropriate component (fixes #20)
  • Loading branch information
Abb4 authored Aug 13, 2023
2 parents 76784f3 + c5112f2 commit c6d0bff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 8 additions & 5 deletions entities/shared/NavMesh2DSeeker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Godot;
using Godot.Collections;

using utilities;

namespace Shared;

public partial class NavMesh2DSeeker : CharacterBody2D
Expand All @@ -11,12 +13,13 @@ public partial class NavMesh2DSeeker : CharacterBody2D

[Export] public int MovementSpeed = 100;

[Export] public NavigateTowards2dNodes navigationComponent;

public override void _Ready()
{
navigationComponent.Targets = Targets;
navigationComponent.MovementSpeed = MovementSpeed;
navigationComponent.StopAfterLastTargetReached = StopAfterLastTargetReached;
if(this.TryFindNodeInChildrenRecursively<NavigateTowards2dNodes>(out var navigationComponent))
{
navigationComponent.Targets = Targets;
navigationComponent.MovementSpeed = MovementSpeed;
navigationComponent.StopAfterLastTargetReached = StopAfterLastTargetReached;
}
}
}
11 changes: 5 additions & 6 deletions entities/shared/nav_mesh_2d_seeker.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[gd_scene load_steps=6 format=3 uid="uid://crupla8b4exdv"]

[ext_resource type="Script" path="res://entities/shared/NavMesh2DSeeker.cs" id="1_1fhc6"]
[ext_resource type="Script" path="res://entities/shared/NavMesh2DSeeker.cs" id="1_okc87"]
[ext_resource type="Script" path="res://entities/shared/NavigateTowards2dNodes.cs" id="1_v72mj"]
[ext_resource type="Texture2D" uid="uid://wjwfy0e7jfxb" path="res://icon.svg" id="1_wiouv"]
[ext_resource type="Script" path="res://entities/shared/NavigateTowards2dNodes.cs" id="2_gkywp"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_okq0l"]
size = Vector2(64, 64)
Expand All @@ -18,19 +18,18 @@ animations = [{
"speed": 5.0
}]

[node name="NavMesh2DSeeker" type="CharacterBody2D" node_paths=PackedStringArray("Targets", "navigationComponent")]
[node name="NavMesh2DSeeker" type="CharacterBody2D" node_paths=PackedStringArray("Targets")]
z_index = 1
script = ExtResource("1_1fhc6")
script = ExtResource("1_okc87")
Targets = []
navigationComponent = NodePath("NavigateTowards2dNodes")

[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
path_desired_distance = 80.0
target_desired_distance = 80.0
debug_enabled = true

[node name="NavigateTowards2dNodes" type="Node" parent="." node_paths=PackedStringArray("Parent", "NavigationAgent2D", "Targets")]
script = ExtResource("2_gkywp")
script = ExtResource("1_v72mj")
Parent = NodePath("..")
NavigationAgent2D = NodePath("../NavigationAgent2D")
Targets = []
Expand Down

0 comments on commit c6d0bff

Please sign in to comment.