From c024783ec800b4569ef424de20adbe8dbd4cac86 Mon Sep 17 00:00:00 2001 From: Haze Weathers Date: Thu, 23 Feb 2023 15:54:27 -0500 Subject: [PATCH] make turning platforms be one-way only when player is inside of them already --- .../environment/turniwood/turning_platform.gd | 12 ++++++++++++ .../turniwood/turning_platform.tscn | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/objects/environment/turniwood/turning_platform.gd b/objects/environment/turniwood/turning_platform.gd index 0f34719..469eb12 100644 --- a/objects/environment/turniwood/turning_platform.gd +++ b/objects/environment/turniwood/turning_platform.gd @@ -2,6 +2,7 @@ extends Node2D onready var anims = $AnimationPlayer onready var flip_timer = $FlipTimer onready var delay_timer = $DelayTimer +onready var collision_shape = $StaticBody2D/CollisionShape2D export var time:float = 60 export var delay = 0.0 export(int, "Wood", "Yellow") var color @@ -28,3 +29,14 @@ func _on_FlipTimer_timeout(): func _on_DelayTimer_timeout(): anims.play("idle") flip_timer.start(time_ms) + + +func _on_DetectPlayer_area_entered(area): + if area.is_in_group("player"): + Debug.print("player in") + collision_shape.set_deferred("one_way_collision", true) + +func _on_DetectPlayer_area_exited(area): + if area.is_in_group("player"): + Debug.print("player out") + collision_shape.set_deferred("one_way_collision", false) diff --git a/objects/environment/turniwood/turning_platform.tscn b/objects/environment/turniwood/turning_platform.tscn index e3a50e8..305db13 100644 --- a/objects/environment/turniwood/turning_platform.tscn +++ b/objects/environment/turniwood/turning_platform.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://objects/environment/turniwood/turning_platform.gd" type="Script" id=1] [ext_resource path="res://graphics/turniwood/turning_platform_yellow.png" type="Texture" id=2] @@ -6,6 +6,9 @@ [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 4, 1 ) +[sub_resource type="RectangleShape2D" id=4] +extents = Vector2( 3.5, 0.5 ) + [sub_resource type="Animation" id=2] resource_name = "idle" loop = true @@ -115,7 +118,16 @@ collision_layer = 4 [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] position = Vector2( 4, 4 ) shape = SubResource( 1 ) -one_way_collision = true +one_way_collision_margin = 0.0 + +[node name="DetectPlayer" type="Area2D" parent="."] +collision_layer = 0 +collision_mask = 2 +monitorable = false + +[node name="CollisionShape2D" type="CollisionShape2D" parent="DetectPlayer"] +position = Vector2( 4, 4 ) +shape = SubResource( 4 ) [node name="AnimationPlayer" type="AnimationPlayer" parent="."] anims/idle = SubResource( 2 ) @@ -126,6 +138,8 @@ anims/turn = SubResource( 3 ) [node name="DelayTimer" type="Timer" parent="."] one_shot = true +[connection signal="area_entered" from="DetectPlayer" to="." method="_on_DetectPlayer_area_entered"] +[connection signal="area_exited" from="DetectPlayer" to="." method="_on_DetectPlayer_area_exited"] [connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_AnimationPlayer_animation_finished"] [connection signal="timeout" from="FlipTimer" to="." method="_on_FlipTimer_timeout"] [connection signal="timeout" from="DelayTimer" to="." method="_on_DelayTimer_timeout"]