Navigation now grid based again.

WorldChunkRefactoring
Martin Felis 2023-06-29 23:07:29 +02:00
parent adaf5292fb
commit c8921bfb7b
3 changed files with 32 additions and 21 deletions

View File

@ -115,10 +115,10 @@ public class NavigationComponent : Node
foreach (int index in Enumerable.Range(1, _path.Length - 1)) foreach (int index in Enumerable.Range(1, _path.Length - 1))
{ {
_pathWorldNavigationPoints.Add( _pathWorldNavigationPoints.Add(
new NavigationPoint(TileWorld.GetTileWorldCenterFromOffset(_path[index].OffsetCoords))); new NavigationPoint(TileWorld.GetHexCenterFromOffset(_path[index].OffsetCoords)));
} }
if ((toPositionWorld - TileWorld.GetTileWorldCenterFromOffset(toCell.OffsetCoords)).LengthSquared() > if ((fromPositionWorld - TileWorld.GetHexCenterFromOffset(toCell.OffsetCoords)).LengthSquared() >
Globals.EpsPositionSquared) Globals.EpsPositionSquared)
{ {
// Remove the last one, because it is only the position rounded to HexGrid coordinates. // Remove the last one, because it is only the position rounded to HexGrid coordinates.
@ -148,10 +148,12 @@ public class NavigationComponent : Node
&& navigationPoint.Flags.HasFlag(NavigationPoint.NavigationFlags.Orientation)) && navigationPoint.Flags.HasFlag(NavigationPoint.NavigationFlags.Orientation))
{ {
PlanGridPath(fromTransformWorld.origin, navigationPoint.WorldPosition, navigationPoint.WorldOrientation); PlanGridPath(fromTransformWorld.origin, navigationPoint.WorldPosition, navigationPoint.WorldOrientation);
} else if (navigationPoint.Flags.HasFlag(NavigationPoint.NavigationFlags.Position)) }
else if (navigationPoint.Flags.HasFlag(NavigationPoint.NavigationFlags.Position))
{ {
PlanGridPath(fromTransformWorld.origin, navigationPoint.WorldPosition); PlanGridPath(fromTransformWorld.origin, navigationPoint.WorldPosition);
} else }
else
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -181,10 +183,12 @@ public class NavigationComponent : Node
&& navigationPoint.Flags.HasFlag(NavigationPoint.NavigationFlags.Orientation)) && navigationPoint.Flags.HasFlag(NavigationPoint.NavigationFlags.Orientation))
{ {
PlanDirectPath(fromTransformWorld.origin, navigationPoint.WorldPosition, navigationPoint.WorldOrientation); PlanDirectPath(fromTransformWorld.origin, navigationPoint.WorldPosition, navigationPoint.WorldOrientation);
} else if (navigationPoint.Flags.HasFlag(NavigationPoint.NavigationFlags.Position)) }
else if (navigationPoint.Flags.HasFlag(NavigationPoint.NavigationFlags.Position))
{ {
PlanDirectPath(fromTransformWorld.origin, navigationPoint.WorldPosition); PlanDirectPath(fromTransformWorld.origin, navigationPoint.WorldPosition);
} else }
else
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -212,7 +216,8 @@ public class NavigationComponent : Node
if (_currentGoal.Flags == NavigationPoint.NavigationFlags.Orientation) if (_currentGoal.Flags == NavigationPoint.NavigationFlags.Orientation)
{ {
_currentGoalPositionWorld = worldTransform.origin; _currentGoalPositionWorld = worldTransform.origin;
} else if (_currentGoal.Flags == NavigationPoint.NavigationFlags.Position) }
else if (_currentGoal.Flags == NavigationPoint.NavigationFlags.Position)
{ {
_currentGoalOrientationWorld = worldTransform.basis.Quat(); _currentGoalOrientationWorld = worldTransform.basis.Quat();
} }
@ -252,7 +257,6 @@ public class NavigationComponent : Node
UpdateCurrentGoal(); UpdateCurrentGoal();
ApplyExistingTransform(currentTransformWorld); ApplyExistingTransform(currentTransformWorld);
} }
if (_pathWorldNavigationPoints.Count == 0) if (_pathWorldNavigationPoints.Count == 0)

View File

@ -103,7 +103,7 @@ public class Player : Entity, IInteractionInterface
if (currentTask is TaskQueueComponent.NavigationTask) if (currentTask is TaskQueueComponent.NavigationTask)
{ {
TaskQueueComponent.NavigationTask navigationTask = (TaskQueueComponent.NavigationTask)currentTask; TaskQueueComponent.NavigationTask navigationTask = (TaskQueueComponent.NavigationTask)currentTask;
_navigationComponent.PlanDirectPath(GlobalTransform, navigationTask.NavigationPoint); _navigationComponent.PlanGridPath(GlobalTransform, navigationTask.NavigationPoint);
} }
} }
} }

View File

@ -345,4 +345,11 @@ public class TileWorld : Spatial
GetHeightAtOffset(offsetCoord), GetHeightAtOffset(offsetCoord),
tileCenter.y + ((Mathf.Sqrt(3) / 2) * Mathf.Round(Size * 0.5f))); tileCenter.y + ((Mathf.Sqrt(3) / 2) * Mathf.Round(Size * 0.5f)));
} }
public Vector3 GetHexCenterFromOffset(Vector2 offsetCoord)
{
Vector2 tileCenter = _hexGrid.GetHexCenterFromOffset(offsetCoord);
return new Vector3(tileCenter.x, GetHeightAtOffset(offsetCoord), tileCenter.y);
}
} }