-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CogitoPressureplate: - Physics based Cogito object that uses a RigidBody on a SliderJoint. - Emits signal based on if the plate is pressed down. - Currently doesn't seem to work with the Player itself. - This is currently fully physics based and thus probably more performance-heavy than it needs to be. - SliderJoint is also not the easiest Node to use.
- Loading branch information
1 parent
76da194
commit fd4ab51
Showing
6 changed files
with
203 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
@icon("res://COGITO/Assets/Graphics/Editor/CogitoNodeIcon.svg") | ||
class_name CogitoPressureplate | ||
extends Node3D | ||
|
||
signal object_state_updated(interaction_text: String) #used to display correct interaction prompts | ||
signal plate_activated() | ||
signal plate_deactivated() | ||
signal damage_received(damage_value:float) | ||
|
||
@onready var audio_stream_player_3d = $AudioStreamPlayer3D | ||
@onready var base: StaticBody3D = $Base | ||
|
||
## Sets this pressure plate as active (can be activated etc) | ||
@export var is_usable : bool = true | ||
## Toggle if switchable can be interacted with repeatedly or not. | ||
@export var allows_repeated_interaction : bool = true | ||
## Sound that plays when weighed down. | ||
@export var activation_sound : AudioStream | ||
|
||
## Nodes that will have their interact function called when this switch is used. | ||
@export var objects_call_interact : Array[NodePath] | ||
@export var objects_call_delay : float = 0.0 | ||
|
||
@export_group("Plate settings") | ||
@export var plate_node : Node3D | ||
@export var unweighted_plate_position : Vector3 | ||
@export var weighted_down_plate_position : Vector3 | ||
@export var tween_time : float = .3 | ||
|
||
var is_activated : bool = false | ||
var player_interaction_component : PlayerInteractionComponent | ||
|
||
|
||
func _ready(): | ||
add_to_group("save_object_state") | ||
audio_stream_player_3d.stream = activation_sound | ||
|
||
|
||
func weigh_down(): | ||
audio_stream_player_3d.play() | ||
|
||
is_activated = true | ||
plate_activated.emit() | ||
|
||
if !objects_call_interact: | ||
return | ||
for nodepath in objects_call_interact: | ||
await get_tree().create_timer(objects_call_delay).timeout | ||
if nodepath != null: | ||
var object = get_node(nodepath) | ||
object.interact(player_interaction_component) | ||
|
||
|
||
func _physics_process(_delta: float) -> void: | ||
if !is_activated and (plate_node.position - weighted_down_plate_position).length() <= 0.03: | ||
weigh_down() | ||
if is_activated and (plate_node.position - weighted_down_plate_position).length() > 0.03: | ||
weight_lifted() | ||
|
||
|
||
func weight_lifted(): | ||
is_activated = false | ||
plate_deactivated.emit() | ||
|
||
|
||
func set_state(): | ||
if is_activated: | ||
plate_node.position = weighted_down_plate_position | ||
else: | ||
plate_node.position = unweighted_plate_position | ||
|
||
|
||
func save(): | ||
var state_dict = { | ||
"node_path" : self.get_path(), | ||
"is_activated" : is_activated, | ||
"pos_x" : position.x, | ||
"pos_y" : position.y, | ||
"pos_z" : position.z, | ||
"rot_x" : rotation.x, | ||
"rot_y" : rotation.y, | ||
"rot_z" : rotation.z, | ||
|
||
} | ||
return state_dict | ||
|
||
|
||
func _on_plate_body_exited(body: Node) -> void: | ||
if body is CogitoObject: | ||
print("Pressure plate: ", body, " has exited.") | ||
weight_lifted() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
[gd_scene load_steps=8 format=3 uid="uid://611llvxrvq88"] | ||
|
||
[ext_resource type="Script" path="res://COGITO/CogitoObjects/Cogito_Pressureplate.gd" id="1_56vbk"] | ||
[ext_resource type="AudioStream" uid="uid://0himm415mqex" path="res://COGITO/Assets/Audio/Kenney/UiAudio/switch29.ogg" id="2_pce3q"] | ||
|
||
[sub_resource type="BoxMesh" id="BoxMesh_7xxyv"] | ||
size = Vector3(1, 0.08, 1) | ||
|
||
[sub_resource type="BoxShape3D" id="BoxShape3D_va3qp"] | ||
size = Vector3(1, 0.1, 1) | ||
|
||
[sub_resource type="BoxMesh" id="BoxMesh_6ge50"] | ||
size = Vector3(0.9, 0.1, 0.9) | ||
|
||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_rs8m6"] | ||
albedo_color = Color(0.501961, 0.341176, 0.501961, 1) | ||
|
||
[sub_resource type="BoxShape3D" id="BoxShape3D_3d3yb"] | ||
margin = 0.03 | ||
size = Vector3(0.9, 0.1, 0.9) | ||
|
||
[node name="Cogito_Pressureplate" type="Node3D" node_paths=PackedStringArray("plate_node")] | ||
script = ExtResource("1_56vbk") | ||
activation_sound = ExtResource("2_pce3q") | ||
plate_node = NodePath("Plate") | ||
unweighted_plate_position = Vector3(0, 0.1, 0) | ||
|
||
[node name="Base" type="StaticBody3D" parent="."] | ||
|
||
[node name="Base" type="MeshInstance3D" parent="Base"] | ||
mesh = SubResource("BoxMesh_7xxyv") | ||
skeleton = NodePath("../../..") | ||
|
||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Base"] | ||
shape = SubResource("BoxShape3D_va3qp") | ||
|
||
[node name="Plate" type="RigidBody3D" parent="."] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.09, 0) | ||
axis_lock_linear_x = true | ||
axis_lock_linear_z = true | ||
axis_lock_angular_x = true | ||
axis_lock_angular_y = true | ||
axis_lock_angular_z = true | ||
gravity_scale = -0.8 | ||
can_sleep = false | ||
max_contacts_reported = 1 | ||
contact_monitor = true | ||
|
||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Plate"] | ||
mesh = SubResource("BoxMesh_6ge50") | ||
surface_material_override/0 = SubResource("StandardMaterial3D_rs8m6") | ||
|
||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Plate"] | ||
shape = SubResource("BoxShape3D_3d3yb") | ||
|
||
[node name="SliderJoint3D" type="SliderJoint3D" parent="."] | ||
transform = Transform3D(-4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0, 1, 0, 0, 0) | ||
node_a = NodePath("../Base") | ||
node_b = NodePath("../Plate") | ||
linear_limit/upper_distance = 0.09 | ||
linear_limit/lower_distance = 0.0 | ||
|
||
[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="."] | ||
bus = &"SFX" | ||
|
||
[connection signal="body_exited" from="Plate" to="." method="_on_plate_body_exited"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters