Switches now have timers
This commit is contained in:
@@ -48,7 +48,7 @@ shadow_mesh = SubResource("ArrayMesh_1l8qq")
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_rhc2e"]
|
||||
size = Vector3(2.20142, 2.09351, 2.20142)
|
||||
|
||||
[node name="Crate1" type="RigidBody3D" groups=["scene_rigidbody"]]
|
||||
[node name="Crate1" type="RigidBody3D" groups=["scene_rigidbody", "weight"]]
|
||||
collision_layer = 33
|
||||
collision_mask = 125
|
||||
|
||||
|
||||
36
assets/pressure_plate.tscn
Normal file
36
assets/pressure_plate.tscn
Normal file
@@ -0,0 +1,36 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://chr8q10bxnrsa"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/pressure_plate.gd" id="1_hedq3"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_fgd7h"]
|
||||
size = Vector3(1, 0.1, 1)
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5rdai"]
|
||||
albedo_color = Color(0, 0, 0, 1)
|
||||
emission_enabled = true
|
||||
emission = Color(1, 0, 0, 1)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_1618f"]
|
||||
size = Vector3(0.9, 0.15, 0.9)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_piu7w"]
|
||||
size = Vector3(1, 0.1, 1)
|
||||
|
||||
[node name="PressurePlate" type="MeshInstance3D" groups=["switch"]]
|
||||
mesh = SubResource("BoxMesh_fgd7h")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_5rdai")
|
||||
script = ExtResource("1_hedq3")
|
||||
|
||||
[node name="CollisionArea" type="Area3D" parent="."]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="CollisionArea"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0)
|
||||
shape = SubResource("BoxShape3D_1618f")
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="."]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"]
|
||||
shape = SubResource("BoxShape3D_piu7w")
|
||||
|
||||
[connection signal="body_entered" from="CollisionArea" to="." method="_on_collision_area_body_entered"]
|
||||
[connection signal="body_exited" from="CollisionArea" to="." method="_on_collision_area_body_exited"]
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=39 format=4 uid="uid://ddyfy6iosbgsj"]
|
||||
[gd_scene load_steps=41 format=4 uid="uid://ddyfy6iosbgsj"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/LevelManager.gd" id="1_jjeos"]
|
||||
[ext_resource type="PackedScene" uid="uid://b5eclfg0cmmal" path="res://assets/revolver_1.tscn" id="2_7dd4i"]
|
||||
@@ -14,6 +14,8 @@
|
||||
[ext_resource type="Script" path="res://levels/switchcontroller.gd" id="11_wstss"]
|
||||
[ext_resource type="Script" path="res://scripts/switch_interactandshoot.gd" id="12_yaq57"]
|
||||
[ext_resource type="Script" path="res://levels/switch_target.gd" id="13_v1s63"]
|
||||
[ext_resource type="PackedScene" uid="uid://chr8q10bxnrsa" path="res://assets/pressure_plate.tscn" id="15_e5ppe"]
|
||||
[ext_resource type="PackedScene" uid="uid://cnfc8rtk6l1d8" path="res://assets/crate1.tscn" id="16_cda17"]
|
||||
|
||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_y04oh"]
|
||||
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
|
||||
@@ -462,9 +464,11 @@ libraries = {
|
||||
}
|
||||
|
||||
[node name="switch" parent="Door1" groups=["interact"] instance=ExtResource("10_lktr8")]
|
||||
transform = Transform3D(1.655, 0, 0, 0, 1.655, 0, 0, 0, 1.655, 18.839, 24.696, 0)
|
||||
transform = Transform3D(1.655, 0, 0, 0, 1.655, 0, 0, 0, 1.655, 18.8615, 24.7082, -0.0258007)
|
||||
skeleton = NodePath("../..")
|
||||
script = ExtResource("12_yaq57")
|
||||
timer_enabled = true
|
||||
timer_duration = 1.0
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="Door1/switch" groups=["interact", "switch"]]
|
||||
script = ExtResource("13_v1s63")
|
||||
@@ -472,30 +476,11 @@ script = ExtResource("13_v1s63")
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Door1/switch/StaticBody3D"]
|
||||
shape = SubResource("SphereShape3D_vyys8")
|
||||
|
||||
[node name="switch2" parent="Door1" groups=["interact"] instance=ExtResource("10_lktr8")]
|
||||
transform = Transform3D(1.655, 0, 0, 0, 1.655, 0, 0, 0, 1.655, 2.06374, 11.8273, -19.0215)
|
||||
[node name="PressurePlate" parent="Door1" instance=ExtResource("15_e5ppe")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15.5014, -0.000858784, -0.799145)
|
||||
skeleton = NodePath("../..")
|
||||
script = ExtResource("12_yaq57")
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="Door1/switch2" groups=["interact", "switch"]]
|
||||
script = ExtResource("13_v1s63")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Door1/switch2/StaticBody3D"]
|
||||
shape = SubResource("SphereShape3D_vyys8")
|
||||
|
||||
[node name="switch3" parent="Door1" groups=["interact"] instance=ExtResource("10_lktr8")]
|
||||
transform = Transform3D(1.655, 0, 0, 0, 1.655, 0, 0, 0, 1.655, 5.3251, 0.640042, -17.4136)
|
||||
skeleton = NodePath("../..")
|
||||
script = ExtResource("12_yaq57")
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="Door1/switch3" groups=["interact", "switch"]]
|
||||
script = ExtResource("13_v1s63")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Door1/switch3/StaticBody3D"]
|
||||
shape = SubResource("SphereShape3D_vyys8")
|
||||
[node name="Crate1" parent="." instance=ExtResource("16_cda17")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15.7658, 1.2863, -3.14915)
|
||||
|
||||
[connection signal="switch_hit" from="Door1/switch/StaticBody3D" to="Door1/switch" method="_on_static_body_3d_switch_hit"]
|
||||
[connection signal="switch_hit" from="Door1/switch2/StaticBody3D" to="Door1/switch2" method="_on_static_body_3d_switch_hit"]
|
||||
[connection signal="switch_on" from="Door1/switch3" to="Door1" method="_on_switch_3_switch_on"]
|
||||
[connection signal="switch_on" from="Door1/switch3" to="Door1/switch3" method="_on_switch_on"]
|
||||
[connection signal="switch_hit" from="Door1/switch3/StaticBody3D" to="Door1/switch3" method="_on_static_body_3d_switch_hit"]
|
||||
|
||||
@@ -18,6 +18,7 @@ config/icon="res://icon.svg"
|
||||
[autoload]
|
||||
|
||||
SignalBus="*res://scripts/signal_bus.gd"
|
||||
SwitchBasic="*res://scripts/switch_basic.gd"
|
||||
|
||||
[display]
|
||||
|
||||
@@ -37,6 +38,7 @@ weapon_pickup=""
|
||||
interact="interactable objects"
|
||||
switch=""
|
||||
scene_rigidbody=""
|
||||
weight=""
|
||||
|
||||
[input]
|
||||
|
||||
|
||||
11
scripts/pressure_plate.gd
Normal file
11
scripts/pressure_plate.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends SwitchBasic
|
||||
|
||||
func _on_collision_area_body_entered(body: Node3D) -> void:
|
||||
if body.is_in_group("weight"):
|
||||
switched_on = true
|
||||
SignalBus.emit_signal("switch_changed")
|
||||
|
||||
func _on_collision_area_body_exited(body: Node3D) -> void:
|
||||
if body.is_in_group("weight"):
|
||||
switched_on = false
|
||||
SignalBus.emit_signal("switch_changed")
|
||||
@@ -1,3 +1,4 @@
|
||||
extends Node
|
||||
|
||||
signal switch_changed()
|
||||
signal switch_timeout()
|
||||
|
||||
@@ -1,12 +1,45 @@
|
||||
extends Node
|
||||
|
||||
@export var start_on : bool = false
|
||||
@export var toggle_enabled : bool = false
|
||||
@export var bullet_enabled : bool = true
|
||||
@export var timer_enabled : bool = false
|
||||
@export var timer_duration : float = 2.0
|
||||
|
||||
var switched_on : bool
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
add_to_group("switch")
|
||||
add_to_group("interact")
|
||||
|
||||
switched_on = start_on
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func switch():
|
||||
if toggle_enabled:
|
||||
if switched_on == true:
|
||||
switched_on = false
|
||||
SignalBus.emit_signal("switch_changed")
|
||||
else:
|
||||
switched_on = true
|
||||
SignalBus.emit_signal("switch_changed")
|
||||
if timer_enabled:
|
||||
start_timer()
|
||||
else:
|
||||
switched_on = true
|
||||
SignalBus.emit_signal("switch_changed")
|
||||
if timer_enabled:
|
||||
start_timer()
|
||||
|
||||
func start_timer():
|
||||
await get_tree().create_timer(timer_duration).timeout
|
||||
_on_timer_timeout()
|
||||
|
||||
func _on_timer_timeout():
|
||||
switched_on = false
|
||||
SignalBus.emit_signal("switch_changed")
|
||||
|
||||
@@ -1,40 +1,8 @@
|
||||
extends Node3D
|
||||
|
||||
var switched_on
|
||||
|
||||
@export var start_on : bool = false
|
||||
@export var toggle_enabled : bool = false
|
||||
@export var bullet_enabled : bool = true
|
||||
@export var timer_enabled : bool = false
|
||||
@export var timer_duration : float = 2.0
|
||||
|
||||
signal switch_on()
|
||||
signal switch_off()
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
add_to_group("switch")
|
||||
add_to_group("interact")
|
||||
switched_on = start_on
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
extends SwitchBasic
|
||||
|
||||
func interact():
|
||||
if toggle_enabled:
|
||||
if switched_on == true:
|
||||
switched_on = false
|
||||
SignalBus.emit_signal("switch_changed")
|
||||
else:
|
||||
switched_on = true
|
||||
SignalBus.emit_signal("switch_changed")
|
||||
else:
|
||||
switched_on = true
|
||||
SignalBus.emit_signal("switch_changed")
|
||||
|
||||
switch()
|
||||
|
||||
func _on_static_body_3d_switch_hit() -> void:
|
||||
if bullet_enabled:
|
||||
interact()
|
||||
switch()
|
||||
|
||||
Reference in New Issue
Block a user