Demo: Simple avoidance using collision shapes

This commit is contained in:
Serhii Snitsaruk 2024-02-01 15:44:27 +01:00
parent d0ff58052d
commit 92ecc17a44
5 changed files with 30 additions and 7 deletions

View File

@ -43,7 +43,7 @@ size = Vector2(100, 35)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_26abe"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_26abe"]
size = Vector2(70, 35) 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"] [sub_resource type="Animation" id="Animation_nvm4d"]
resource_name = "RESET" resource_name = "RESET"
@ -3424,7 +3424,11 @@ _data = {
} }
[node name="AgentBase" type="CharacterBody2D"] [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") script = ExtResource("1_n8vy2")
[node name="Root" type="Node2D" parent="."] [node name="Root" type="Node2D" parent="."]
@ -3535,7 +3539,7 @@ metadata/_edit_lock_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(-1, -7) position = Vector2(-1, -7)
rotation = 1.5708 rotation = 1.5708
shape = SubResource("CapsuleShape2D_aa16q") shape = SubResource("CircleShape2D_0c228")
[node name="Health" type="Node" parent="."] [node name="Health" type="Node" parent="."]
script = ExtResource("4_qwtrf") script = ExtResource("4_qwtrf")

View File

@ -7,6 +7,8 @@
[ext_resource type="Script" path="res://demo/agents/player/states/attack_state.gd" id="5_mpgu6"] [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")] [node name="Player" groups=["player"] instance=ExtResource("1_mswd4")]
collision_layer = 0
collision_mask = 1
script = ExtResource("2_24nyi") script = ExtResource("2_24nyi")
[node name="Hitbox" parent="Root" index="3"] [node name="Hitbox" parent="Root" index="3"]

View File

@ -17,6 +17,7 @@ const NinjaStar := preload("res://demo/agents/ninja_star/ninja_star.tscn")
@onready var animation_player: AnimationPlayer = $AnimationPlayer @onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var health: Health = $Health @onready var health: Health = $Health
@onready var root: Node2D = $Root @onready var root: Node2D = $Root
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D
var _frames_since_facing_update: int = 0 var _frames_since_facing_update: int = 0
var _is_dead: bool = false var _is_dead: bool = false
@ -74,6 +75,7 @@ func _damaged(_amount: float) -> void:
func _die() -> void: func _die() -> void:
_is_dead = true _is_dead = true
animation_player.play(&"death") animation_player.play(&"death")
collision_shape_2d.set_deferred(&"disabled", true)
for child in get_children(): for child in get_children():
if child is BTPlayer or child is LimboHSM: if child is BTPlayer or child is LimboHSM:

View File

@ -2873,6 +2873,24 @@ metadata/_edit_lock_ = true
y_sort_enabled = true y_sort_enabled = true
metadata/_edit_lock_ = 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")] [node name="Player" parent="YSort/Agents" instance=ExtResource("5_cmgoj")]
position = Vector2(633, 256) position = Vector2(633, 256)
@ -2886,9 +2904,6 @@ drag_vertical_enabled = true
drag_top_margin = 0.1 drag_top_margin = 0.1
drag_bottom_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")] [node name="AgentRanged" parent="YSort/Agents" instance=ExtResource("6_76icr")]
position = Vector2(2067, 543) position = Vector2(2067, 543)

View File

@ -55,7 +55,7 @@ attack={
[layer_names] [layer_names]
2d_physics/layer_1="Obstacle" 2d_physics/layer_1="Obstacle"
2d_physics/layer_2="Player" 2d_physics/layer_2="Agent"
2d_physics/layer_3="BoxPlayer" 2d_physics/layer_3="BoxPlayer"
2d_physics/layer_4="BoxEnemy" 2d_physics/layer_4="BoxEnemy"