From 92ecc17a444f0d5c91396d53f489ee0fe03dea2d Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Thu, 1 Feb 2024 15:44:27 +0100 Subject: [PATCH] Demo: Simple avoidance using collision shapes --- demo/demo/agents/agent_base.tscn | 10 +++++++--- demo/demo/agents/player/player.tscn | 2 ++ demo/demo/agents/scripts/agent_base.gd | 2 ++ demo/demo/scenes/demo.tscn | 21 ++++++++++++++++++--- demo/project.godot | 2 +- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/demo/demo/agents/agent_base.tscn b/demo/demo/agents/agent_base.tscn index b27e019..872569c 100644 --- a/demo/demo/agents/agent_base.tscn +++ b/demo/demo/agents/agent_base.tscn @@ -43,7 +43,7 @@ size = Vector2(100, 35) [sub_resource type="RectangleShape2D" id="RectangleShape2D_26abe"] size = Vector2(70, 35) -[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_aa16q"] +[sub_resource type="CircleShape2D" id="CircleShape2D_0c228"] [sub_resource type="Animation" id="Animation_nvm4d"] resource_name = "RESET" @@ -3424,7 +3424,11 @@ _data = { } [node name="AgentBase" type="CharacterBody2D"] -collision_layer = 0 +collision_layer = 2 +collision_mask = 3 +motion_mode = 1 +wall_min_slide_angle = 0.0174533 +safe_margin = 0.001 script = ExtResource("1_n8vy2") [node name="Root" type="Node2D" parent="."] @@ -3535,7 +3539,7 @@ metadata/_edit_lock_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(-1, -7) rotation = 1.5708 -shape = SubResource("CapsuleShape2D_aa16q") +shape = SubResource("CircleShape2D_0c228") [node name="Health" type="Node" parent="."] script = ExtResource("4_qwtrf") diff --git a/demo/demo/agents/player/player.tscn b/demo/demo/agents/player/player.tscn index 8ee8d6f..7b24e93 100644 --- a/demo/demo/agents/player/player.tscn +++ b/demo/demo/agents/player/player.tscn @@ -7,6 +7,8 @@ [ext_resource type="Script" path="res://demo/agents/player/states/attack_state.gd" id="5_mpgu6"] [node name="Player" groups=["player"] instance=ExtResource("1_mswd4")] +collision_layer = 0 +collision_mask = 1 script = ExtResource("2_24nyi") [node name="Hitbox" parent="Root" index="3"] diff --git a/demo/demo/agents/scripts/agent_base.gd b/demo/demo/agents/scripts/agent_base.gd index b7e2376..7d86baf 100644 --- a/demo/demo/agents/scripts/agent_base.gd +++ b/demo/demo/agents/scripts/agent_base.gd @@ -17,6 +17,7 @@ const NinjaStar := preload("res://demo/agents/ninja_star/ninja_star.tscn") @onready var animation_player: AnimationPlayer = $AnimationPlayer @onready var health: Health = $Health @onready var root: Node2D = $Root +@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D var _frames_since_facing_update: int = 0 var _is_dead: bool = false @@ -74,6 +75,7 @@ func _damaged(_amount: float) -> void: func _die() -> void: _is_dead = true animation_player.play(&"death") + collision_shape_2d.set_deferred(&"disabled", true) for child in get_children(): if child is BTPlayer or child is LimboHSM: diff --git a/demo/demo/scenes/demo.tscn b/demo/demo/scenes/demo.tscn index 6f39d4c..a125238 100644 --- a/demo/demo/scenes/demo.tscn +++ b/demo/demo/scenes/demo.tscn @@ -2873,6 +2873,24 @@ metadata/_edit_lock_ = true y_sort_enabled = true metadata/_edit_lock_ = true +[node name="AgentMeleeNuanced" parent="YSort/Agents" instance=ExtResource("8_ovfbp")] +position = Vector2(1513, 262) + +[node name="AgentMeleeNuanced3" parent="YSort/Agents" instance=ExtResource("8_ovfbp")] +position = Vector2(1125, 748) + +[node name="AgentMeleeNuanced4" parent="YSort/Agents" instance=ExtResource("8_ovfbp")] +position = Vector2(227, 231) + +[node name="AgentMeleeNuanced5" parent="YSort/Agents" instance=ExtResource("8_ovfbp")] +position = Vector2(592, -163) + +[node name="AgentMeleeNuanced6" parent="YSort/Agents" instance=ExtResource("8_ovfbp")] +position = Vector2(1589, -87) + +[node name="AgentMeleeNuanced7" parent="YSort/Agents" instance=ExtResource("8_ovfbp")] +position = Vector2(-154, 726) + [node name="Player" parent="YSort/Agents" instance=ExtResource("5_cmgoj")] position = Vector2(633, 256) @@ -2886,9 +2904,6 @@ drag_vertical_enabled = true drag_top_margin = 0.1 drag_bottom_margin = 0.1 -[node name="AgentMeleeNuanced" parent="YSort/Agents" instance=ExtResource("8_ovfbp")] -position = Vector2(-180, 552) - [node name="AgentRanged" parent="YSort/Agents" instance=ExtResource("6_76icr")] position = Vector2(2067, 543) diff --git a/demo/project.godot b/demo/project.godot index ac78ed5..daba808 100644 --- a/demo/project.godot +++ b/demo/project.godot @@ -55,7 +55,7 @@ attack={ [layer_names] 2d_physics/layer_1="Obstacle" -2d_physics/layer_2="Player" +2d_physics/layer_2="Agent" 2d_physics/layer_3="BoxPlayer" 2d_physics/layer_4="BoxEnemy"