From 3e90e3fad045dbc8d572cd388646f248b1b94d9a Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Wed, 15 Feb 2023 20:59:22 +0100 Subject: [PATCH] Minor improvements? --- components/NavigationComponent.cs | 9 +++++++++ entities/Flower.cs | 33 ------------------------------- project.godot | 8 ++++---- scenes/Game.tscn | 31 +---------------------------- 4 files changed, 14 insertions(+), 67 deletions(-) delete mode 100644 entities/Flower.cs diff --git a/components/NavigationComponent.cs b/components/NavigationComponent.cs index 1b49c83..beca70d 100644 --- a/components/NavigationComponent.cs +++ b/components/NavigationComponent.cs @@ -48,6 +48,7 @@ public class NavigationComponent : Node { bool goalReached = false; float positionErrorSquared = (worldTransform.origin - WorldPosition).LengthSquared(); + Quat own_orientation = worldTransform.basis.Quat(); float orientationError = Mathf.Abs(worldTransform.basis.Quat().AngleTo(WorldOrientation)); if (Flags.HasFlag(NavigationPoint.NavigationFlags.Position) @@ -165,6 +166,8 @@ public class NavigationComponent : Node } _currentGoal = _pathWorldNavigationPoints[0]; + _currentGoalPositionWorld = _pathWorldNavigationPoints[0].WorldPosition; + _currentGoalOrientationWorld = _pathWorldNavigationPoints[0].WorldOrientation; GD.Print("Navigation Goal: pos " + _currentGoal.WorldPosition + " " + " rot: " + _currentGoal.WorldOrientation + " flags: " + _currentGoal.Flags + " path length: " + @@ -202,5 +205,11 @@ public class NavigationComponent : Node _pathWorldNavigationPoints.RemoveAt(0); UpdateCurrentGoal(); } + + if (_pathWorldNavigationPoints.Count == 0) + { + _currentGoalOrientationWorld = currentTransformWorld.basis.Quat(); + _currentGoalPositionWorld = currentTransformWorld.origin; + } } } \ No newline at end of file diff --git a/entities/Flower.cs b/entities/Flower.cs deleted file mode 100644 index 2f6089e..0000000 --- a/entities/Flower.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Godot; -using Godot.Collections; - -namespace GodotComponentTest.entities; - -public class Flower : Entity -{ - public override void _Ready() - { - Array children = new Array(); - GetAllChildren(this, ref children); - - foreach (Node child in children) - { - if (child is ClickableComponent) - { - GD.Print("Found Clickable Component!"); - } - } - } - - void GetAllChildren(Node childNode, ref Array childList) - { - var children = childNode.GetChildren(); - foreach (Node child in children) - { - childList.Add(child); - GetAllChildren(child, ref childList); - } - } -} \ No newline at end of file diff --git a/project.godot b/project.godot index abce6f2..d772b01 100644 --- a/project.godot +++ b/project.godot @@ -9,17 +9,17 @@ config_version=4 _global_script_classes=[ { -"base": "Reference", +"base": "Node", "class": "ClickableComponent", "language": "GDScript", "path": "res://components/ClickableComponent.gd" }, { -"base": "Reference", +"base": "KinematicBody2D", "class": "CollisionLine", "language": "GDScript", "path": "res://utils/CollisionLine.gd" }, { -"base": "Reference", +"base": "Node", "class": "ColorComponent", "language": "GDScript", "path": "res://components/ColorComponent.gd" @@ -54,7 +54,7 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://utils/SpringDamper.gd" }, { -"base": "Reference", +"base": "Sprite", "class": "TintedSpriteComponent", "language": "GDScript", "path": "res://components/TintedSpriteComponent.gd" diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 3030a06..fd732c6 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=27 format=2] +[gd_scene load_steps=22 format=2] [ext_resource path="res://scenes/StreamContainer.cs" type="Script" id=1] [ext_resource path="res://components/NavigationComponent.cs" type="Script" id=2] @@ -11,8 +11,6 @@ [ext_resource path="res://scenes/Game.cs" type="Script" id=9] [ext_resource path="res://scenes/DebugCamera.gd" type="Script" id=10] [ext_resource path="res://assets/CreatusPiratePack/characters/Pirate1final_0.01.glb" type="PackedScene" id=13] -[ext_resource path="res://components/ClickableComponent.cs" type="Script" id=14] -[ext_resource path="res://entities/Flower.cs" type="Script" id=15] [sub_resource type="OpenSimplexNoise" id=10] period = 39.6 @@ -49,13 +47,6 @@ radial_segments = 16 [sub_resource type="PrismMesh" id=15] -[sub_resource type="CubeMesh" id=17] - -[sub_resource type="BoxShape" id=18] -extents = Vector3( 0.2, 0.2, 0.2 ) - -[sub_resource type="BoxShape" id=19] - [node name="Game" type="Spatial"] script = ExtResource( 9 ) @@ -288,26 +279,6 @@ script = ExtResource( 2 ) [node name="Chest" parent="Entities" instance=ExtResource( 7 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.01499, 0, -1.3224 ) -[node name="Flower" type="KinematicBody" parent="Entities"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 3.75737, 0, -3.73012 ) -script = ExtResource( 15 ) - -[node name="MeshInstance" type="MeshInstance" parent="Entities/Flower"] -transform = Transform( 0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0 ) -mesh = SubResource( 17 ) - -[node name="CollisionShape" type="CollisionShape" parent="Entities/Flower"] -shape = SubResource( 18 ) - -[node name="ClickableComponent" type="Spatial" parent="Entities/Flower"] -script = ExtResource( 14 ) - -[node name="Area" type="Area" parent="Entities/Flower/ClickableComponent"] - -[node name="CollisionShape" type="CollisionShape" parent="Entities/Flower/ClickableComponent/Area"] -transform = Transform( 0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0 ) -shape = SubResource( 19 ) - [node name="Chest3" parent="Entities" instance=ExtResource( 7 )] transform = Transform( 0.550568, 0, -0.83479, 0, 1, 0, 0.83479, 0, 0.550568, 4.88275, 0, -1.70504 )