New navigation

This commit is contained in:
Marco 2025-04-09 11:43:44 +02:00
commit 86f7459837
8 changed files with 119 additions and 56 deletions

View file

@ -64,6 +64,8 @@ public partial class GameManager : Node2D
[Export]
public int EggStartIndex = 0;
[Export] public NavigationRegion2D NavigationRegion { get; private set; }
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
@ -143,6 +145,8 @@ public partial class GameManager : Node2D
{
Unpause();
}
}
private void DelayPlayerSpawn()
@ -365,12 +369,20 @@ public partial class GameManager : Node2D
public void RecalculateTilemap(Vector2 position)
{
CallDeferred(MethodName.RecalculateTilemapDeferred, position);
//CallDeferred(MethodName.RecalculateTilemapDeferred, position);
}
private void RecalculateTilemapDeferred(Vector2 position)
{
NavigationTilemap.Recalculate(position);
//NavigationTilemap.Recalculate(position);
GD.Print("Rebaking tilemap");
NavigationRegion.BakeNavigationPolygon(true);
}
public void RebakeNavigation()
{
GD.Print("Rebaking tilemap");
//NavigationRegion.BakeNavigationPolygon(true);
}
}

View file

@ -14,7 +14,7 @@ public partial class TilemapAvoidance : TileMapLayer
public override void _Ready()
{
//NavigationServer2D.MapSetEdgeConnectionMargin(this.TileSet.GetRid(), 0f);
_ = RefreshNavigationAsync();
//_ = RefreshNavigationAsync();
}
@ -41,16 +41,16 @@ public partial class TilemapAvoidance : TileMapLayer
//
if (_needsFullCheck)
{
var spaceState = GetWorld2D().DirectSpaceState;
var globalCoords = ToGlobal(this.MapToLocal(coords));
var query = new PhysicsPointQueryParameters2D();
query.Position = globalCoords;
query.CollisionMask = ObstaclesCollisionMask;
query.CollideWithBodies = true;
query.CollideWithAreas = true;
var result = spaceState.IntersectPoint(query);
if (result.Count > 0) return true;
// var spaceState = GetWorld2D().DirectSpaceState;
// var globalCoords = ToGlobal(this.MapToLocal(coords));
// var query = new PhysicsPointQueryParameters2D();
// query.Position = globalCoords;
// query.CollisionMask = ObstaclesCollisionMask;
// query.CollideWithBodies = true;
// query.CollideWithAreas = true;
//
// var result = spaceState.IntersectPoint(query);
// if (result.Count > 0) return true;
//_needsFullCheck = false;
return _solidLayers.Aggregate(false,