Minor cleanup path smoothing and entities scenes.

WorldChunkRefactoring
Martin Felis 2023-07-14 17:56:01 +02:00
parent 42d7658d03
commit efb934c441
9 changed files with 30 additions and 19 deletions

View File

@ -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;
}

View File

@ -206,36 +206,43 @@ public class NavigationComponent : Spatial
public List<NavigationPoint> SmoothPath(KinematicBody body, List<NavigationPoint> navigationPoints)
{
Debug.Assert(navigationPoints.Count > 2);
Vector3 bodyGlobalTranslation = body.GlobalTranslation;
List<NavigationPoint> smoothedPath = new List<NavigationPoint>();
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);

View File

@ -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;

View File

@ -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="."]

View File

@ -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"]

View File

@ -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 )]

View File

@ -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]