Minor improvements?

WorldChunkRefactoring
Martin Felis 2023-02-15 20:59:22 +01:00
parent 3a652ef683
commit 3e90e3fad0
4 changed files with 14 additions and 67 deletions

View File

@ -48,6 +48,7 @@ public class NavigationComponent : Node
{ {
bool goalReached = false; bool goalReached = false;
float positionErrorSquared = (worldTransform.origin - WorldPosition).LengthSquared(); float positionErrorSquared = (worldTransform.origin - WorldPosition).LengthSquared();
Quat own_orientation = worldTransform.basis.Quat();
float orientationError = Mathf.Abs(worldTransform.basis.Quat().AngleTo(WorldOrientation)); float orientationError = Mathf.Abs(worldTransform.basis.Quat().AngleTo(WorldOrientation));
if (Flags.HasFlag(NavigationPoint.NavigationFlags.Position) if (Flags.HasFlag(NavigationPoint.NavigationFlags.Position)
@ -165,6 +166,8 @@ public class NavigationComponent : Node
} }
_currentGoal = _pathWorldNavigationPoints[0]; _currentGoal = _pathWorldNavigationPoints[0];
_currentGoalPositionWorld = _pathWorldNavigationPoints[0].WorldPosition;
_currentGoalOrientationWorld = _pathWorldNavigationPoints[0].WorldOrientation;
GD.Print("Navigation Goal: pos " + _currentGoal.WorldPosition + " " + " rot: " + _currentGoal.WorldOrientation + GD.Print("Navigation Goal: pos " + _currentGoal.WorldPosition + " " + " rot: " + _currentGoal.WorldOrientation +
" flags: " + _currentGoal.Flags + " path length: " + " flags: " + _currentGoal.Flags + " path length: " +
@ -202,5 +205,11 @@ public class NavigationComponent : Node
_pathWorldNavigationPoints.RemoveAt(0); _pathWorldNavigationPoints.RemoveAt(0);
UpdateCurrentGoal(); UpdateCurrentGoal();
} }
if (_pathWorldNavigationPoints.Count == 0)
{
_currentGoalOrientationWorld = currentTransformWorld.basis.Quat();
_currentGoalPositionWorld = currentTransformWorld.origin;
}
} }
} }

View File

@ -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<Node> children = new Array<Node>();
GetAllChildren(this, ref children);
foreach (Node child in children)
{
if (child is ClickableComponent)
{
GD.Print("Found Clickable Component!");
}
}
}
void GetAllChildren(Node childNode, ref Array<Node> childList)
{
var children = childNode.GetChildren();
foreach (Node child in children)
{
childList.Add(child);
GetAllChildren(child, ref childList);
}
}
}

View File

@ -9,17 +9,17 @@
config_version=4 config_version=4
_global_script_classes=[ { _global_script_classes=[ {
"base": "Reference", "base": "Node",
"class": "ClickableComponent", "class": "ClickableComponent",
"language": "GDScript", "language": "GDScript",
"path": "res://components/ClickableComponent.gd" "path": "res://components/ClickableComponent.gd"
}, { }, {
"base": "Reference", "base": "KinematicBody2D",
"class": "CollisionLine", "class": "CollisionLine",
"language": "GDScript", "language": "GDScript",
"path": "res://utils/CollisionLine.gd" "path": "res://utils/CollisionLine.gd"
}, { }, {
"base": "Reference", "base": "Node",
"class": "ColorComponent", "class": "ColorComponent",
"language": "GDScript", "language": "GDScript",
"path": "res://components/ColorComponent.gd" "path": "res://components/ColorComponent.gd"
@ -54,7 +54,7 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://utils/SpringDamper.gd" "path": "res://utils/SpringDamper.gd"
}, { }, {
"base": "Reference", "base": "Sprite",
"class": "TintedSpriteComponent", "class": "TintedSpriteComponent",
"language": "GDScript", "language": "GDScript",
"path": "res://components/TintedSpriteComponent.gd" "path": "res://components/TintedSpriteComponent.gd"

View File

@ -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://scenes/StreamContainer.cs" type="Script" id=1]
[ext_resource path="res://components/NavigationComponent.cs" type="Script" id=2] [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/Game.cs" type="Script" id=9]
[ext_resource path="res://scenes/DebugCamera.gd" type="Script" id=10] [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://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] [sub_resource type="OpenSimplexNoise" id=10]
period = 39.6 period = 39.6
@ -49,13 +47,6 @@ radial_segments = 16
[sub_resource type="PrismMesh" id=15] [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"] [node name="Game" type="Spatial"]
script = ExtResource( 9 ) script = ExtResource( 9 )
@ -288,26 +279,6 @@ script = ExtResource( 2 )
[node name="Chest" parent="Entities" instance=ExtResource( 7 )] [node name="Chest" parent="Entities" instance=ExtResource( 7 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.01499, 0, -1.3224 ) 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 )] [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 ) transform = Transform( 0.550568, 0, -0.83479, 0, 1, 0, 0.83479, 0, 0.550568, 4.88275, 0, -1.70504 )