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

@ -62,6 +62,7 @@ public partial class Barrel : Area2D, IDestructible
QueueFree();
GameManager.Instance.RebakeNavigation();
//GameManager.Instance.RecalculateTilemap(this.GlobalPosition);
}

File diff suppressed because one or more lines are too long

View file

@ -16,7 +16,7 @@ region = Rect2(0, 0, 16, 16)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ss2y0"]
size = Vector2(11, 14)
[node name="Barrel" type="Area2D" groups=["Destroyable"]]
[node name="Barrel" type="Area2D" groups=["Destroyable", "navigation_polygon_source_geometry_group"]]
collision_layer = 64
collision_mask = 138
script = ExtResource("1_avwdx")
@ -37,10 +37,9 @@ shape = SubResource("RectangleShape2D_2ewfl")
position = Vector2(0, -2)
texture = SubResource("AtlasTexture_v7gy8")
[node name="RigidBody2D" type="RigidBody2D" parent="."]
[node name="RigidBody2D" type="StaticBody2D" parent="." groups=["navigation_polygon_source_geometry_group"]]
collision_layer = 64
collision_mask = 10
gravity_scale = 0.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
visible = false

View file

@ -45,11 +45,10 @@ shape = SubResource("RectangleShape2D_2ewfl")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_mupuc")
[node name="RigidBody2D" type="RigidBody2D" parent="."]
[node name="RigidBody2D" type="StaticBody2D" parent="."]
visible = false
collision_layer = 64
collision_mask = 10
gravity_scale = 0.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
position = Vector2(0, -3)

File diff suppressed because one or more lines are too long

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,

View file

@ -157,6 +157,7 @@ Interactable=""
Solid=""
Acid=""
Destroyable=""
navigation_polygon_source_geometry_group=""
[input]
@ -342,6 +343,10 @@ locale/translations=PackedStringArray("res://Dialogue/Translations/dialogic_char
2d_physics/layer_9="Acid"
2d_physics/layer_10="Conveyor"
[navigation]
2d/use_edge_connections=false
[physics]
common/physics_jitter_fix=0.0