From efb934c441998b36529c580e9353f2e24cf9b3a7 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Fri, 14 Jul 2023 17:56:01 +0200 Subject: [PATCH] Minor cleanup path smoothing and entities scenes. --- components/InteractionComponent.cs | 8 +++--- components/NavigationComponent.cs | 27 ++++++++++++++------- entities/Tree.cs | 2 +- entities/Tree.tscn | 4 +-- {assets/Environment => entities}/rockA.tscn | 1 + {assets/Environment => entities}/rockB.tscn | 0 {assets/Environment => entities}/rockC.tscn | 0 scenes/Game.tscn | 1 + scenes/TileWorld.tscn | 6 ++--- 9 files changed, 30 insertions(+), 19 deletions(-) rename {assets/Environment => entities}/rockA.tscn (97%) rename {assets/Environment => entities}/rockB.tscn (100%) rename {assets/Environment => entities}/rockC.tscn (100%) diff --git a/components/InteractionComponent.cs b/components/InteractionComponent.cs index d4462d4..3f69fce 100644 --- a/components/InteractionComponent.cs +++ b/components/InteractionComponent.cs @@ -5,11 +5,11 @@ namespace GodotComponentTest.components; public class InteractionComponent: Component { [Signal] - delegate void InteractionStart(Entity owningEntity, Entity targetEntity); + delegate void InteractionStart(Spatial owningEntity, Spatial targetEntity); [Signal] - delegate void InteractionEnd(Entity owningEntity, Entity targetEntity); + delegate void InteractionEnd(Spatial owningEntity, Spatial targetEntity); - public Entity OwningEntity; - public Entity TargetEntity; + public Spatial OwningEntity; + public Spatial TargetEntity; } \ No newline at end of file diff --git a/components/NavigationComponent.cs b/components/NavigationComponent.cs index a8fd574..2e6d671 100644 --- a/components/NavigationComponent.cs +++ b/components/NavigationComponent.cs @@ -206,36 +206,43 @@ public class NavigationComponent : Spatial public List SmoothPath(KinematicBody body, List navigationPoints) { Debug.Assert(navigationPoints.Count > 2); - + + Vector3 bodyGlobalTranslation = body.GlobalTranslation; List smoothedPath = new List(); int startIndex = 0; int endIndex = navigationPoints.Count > 1 ? 1 : 0; smoothedPath.Add(navigationPoints[startIndex]); + Vector3 startPoint = navigationPoints[startIndex].WorldPosition; while (endIndex != navigationPoints.Count - 1) { - Vector3 startPoint = navigationPoints[startIndex].WorldPosition; Vector3 endPoint = navigationPoints[endIndex].WorldPosition; if (HasPathCollision(body, startPoint, endPoint)) { if (endIndex - startIndex == 1) { - smoothedPath.Add(navigationPoints[endIndex]); - startIndex = endIndex; + GD.Print("Aborting SmoothPath: input path passes through collision geometry."); + body.GlobalTranslation = bodyGlobalTranslation; + return smoothedPath; } else { smoothedPath.Add(navigationPoints[endIndex - 1]); startIndex = endIndex - 1; + startPoint = navigationPoints[startIndex].WorldPosition; + body.GlobalTranslation = startPoint; + continue; } } endIndex += 1; } + smoothedPath.Add(navigationPoints[endIndex]); - + body.GlobalTranslation = bodyGlobalTranslation; + return smoothedPath; } @@ -335,11 +342,13 @@ public class NavigationComponent : Spatial debugGeometry.GlobalTransform = Transform.Identity; debugGeometry.Begin(Mesh.PrimitiveType.Lines); - debugGeometry.SetColor(Colors.Pink); + Color pinkColor = Colors.Pink; + pinkColor.a = 1; + debugGeometry.SetColor(pinkColor); debugGeometry.AddVertex(parentNode.GlobalTranslation + yOffset); - debugGeometry.SetColor(Colors.Pink); + debugGeometry.SetColor(pinkColor); debugGeometry.AddVertex(CurrentGoalPositionWorld + yOffset); - debugGeometry.SetColor(Colors.Pink); + debugGeometry.SetColor(pinkColor); debugGeometry.PushTranslated(CurrentGoalPositionWorld); debugGeometry.AddBox(Vector3.One * 1); @@ -357,7 +366,7 @@ public class NavigationComponent : Spatial previousPoint = parentNode.GlobalTranslation; foreach (NavigationPoint point in _smoothedPathWorldNavigationPoints) { - debugGeometry.SetColor(Colors.Green); + debugGeometry.SetColor(new Color(0, 0, 1, 1)); debugGeometry.AddVertex(previousPoint + yOffset); debugGeometry.AddVertex(point.WorldPosition + yOffset); diff --git a/entities/Tree.cs b/entities/Tree.cs index 1a8d9d3..a6d30f7 100644 --- a/entities/Tree.cs +++ b/entities/Tree.cs @@ -4,7 +4,7 @@ using System.Diagnostics; using GodotComponentTest.components; using GodotComponentTest.entities; -public class Tree : Entity, IInteractionInterface +public class Tree : StaticBody, IInteractionInterface { [Export] public float ChopDuration = 2; public bool IsMouseOver; diff --git a/entities/Tree.tscn b/entities/Tree.tscn index b526f2e..163423a 100644 --- a/entities/Tree.tscn +++ b/entities/Tree.tscn @@ -106,11 +106,11 @@ tracks/1/keys = { "times": PoolRealArray( 0, 0.05, 0.15, 0.3, 0.4, 0.5, 0.6 ) } -[node name="Tree" type="KinematicBody"] +[node name="Tree" type="StaticBody"] script = ExtResource( 3 ) [node name="Geometry" type="MeshInstance" parent="."] -transform = Transform( 1.5, 0, 0, 0, 0.984722, 0.266325, 0, -0.177712, 1.47574, 0, 0, 0 ) +transform = Transform( 1.5, 0, 0, 0, 0.984723, 0.266325, 0, -0.177712, 1.47574, 0, 0, 0 ) mesh = SubResource( 1 ) [node name="CollisionShape" type="CollisionShape" parent="."] diff --git a/assets/Environment/rockA.tscn b/entities/rockA.tscn similarity index 97% rename from assets/Environment/rockA.tscn rename to entities/rockA.tscn index 8527d4a..096411e 100644 --- a/assets/Environment/rockA.tscn +++ b/entities/rockA.tscn @@ -12,6 +12,7 @@ radius = 0.4 transform = Transform( 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0 ) [node name="StaticBody" type="StaticBody" parent="." index="1"] +collision_mask = 0 input_ray_pickable = false [node name="CollisionShape" type="CollisionShape" parent="StaticBody" index="0"] diff --git a/assets/Environment/rockB.tscn b/entities/rockB.tscn similarity index 100% rename from assets/Environment/rockB.tscn rename to entities/rockB.tscn diff --git a/assets/Environment/rockC.tscn b/entities/rockC.tscn similarity index 100% rename from assets/Environment/rockC.tscn rename to entities/rockC.tscn diff --git a/scenes/Game.tscn b/scenes/Game.tscn index f480500..15f6bcb 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -274,6 +274,7 @@ stretch_mode = 1 flip_v = true [node name="StreamContainer" parent="." instance=ExtResource( 1 )] +ShowHexTiles = true [node name="Camera" parent="." instance=ExtResource( 3 )] diff --git a/scenes/TileWorld.tscn b/scenes/TileWorld.tscn index 33e7ae2..00ebb5a 100644 --- a/scenes/TileWorld.tscn +++ b/scenes/TileWorld.tscn @@ -4,9 +4,9 @@ [ext_resource path="res://icon.png" type="Texture" id=2] [ext_resource path="res://materials/IslandColorRampShader.tres" type="Material" id=3] [ext_resource path="res://materials/IslandHeightmapFalloffShader.tres" type="Material" id=4] -[ext_resource path="res://assets/Environment/rockB.tscn" type="PackedScene" id=5] -[ext_resource path="res://assets/Environment/rockC.tscn" type="PackedScene" id=6] -[ext_resource path="res://assets/Environment/rockA.tscn" type="PackedScene" id=7] +[ext_resource path="res://entities/rockB.tscn" type="PackedScene" id=5] +[ext_resource path="res://entities/rockC.tscn" type="PackedScene" id=6] +[ext_resource path="res://entities/rockA.tscn" type="PackedScene" id=7] [ext_resource path="res://assets/Environment/grassLarge.tscn" type="PackedScene" id=8] [ext_resource path="res://entities/Tree.tscn" type="PackedScene" id=9]