From 1ecbc874004ec02e9a8304f227f1b99b2e23b157 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Thu, 16 Jul 2020 14:36:08 +0200 Subject: [PATCH] Make door automatically open when players bump into them --- Actors/Objects/Door/Door.gd | 3 +++ Actors/Objects/Door/Door.tscn | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Actors/Objects/Door/Door.gd b/Actors/Objects/Door/Door.gd index d42a35d..932ae72 100644 --- a/Actors/Objects/Door/Door.gd +++ b/Actors/Objects/Door/Door.gd @@ -69,3 +69,6 @@ func serialize(): func deserialize(data): pass + +func _open_sensor_triggered(): + rpc("set_open", $Sprite.animation == "close") diff --git a/Actors/Objects/Door/Door.tscn b/Actors/Objects/Door/Door.tscn index 39d6947..d090797 100644 --- a/Actors/Objects/Door/Door.tscn +++ b/Actors/Objects/Door/Door.tscn @@ -42,7 +42,7 @@ animations = [ { } ] [sub_resource type="CircleShape2D" id=8] -radius = 64.0 +radius = 18.0 [node name="Door" type="StaticBody2D"] input_pickable = true @@ -71,8 +71,16 @@ script = ExtResource( 3 ) position = Vector2( 16, 16 ) shape = SubResource( 8 ) +[node name="CloseRange" type="Area2D" parent="."] +script = ExtResource( 3 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="CloseRange"] +position = Vector2( 16, 16 ) +shape = SubResource( 8 ) + [node name="PowerManager" type="Node" parent="."] script = ExtResource( 4 ) power_usage = 2.0 [connection signal="animation_finished" from="Sprite" to="." method="_animation_finished"] [connection signal="timeout" from="Timer" to="." method="_close_timer_triggered"] +[connection signal="player_entered" from="CloseRange" to="." method="_open_sensor_triggered"]