Skip to content

Commit

Permalink
New: CogitoPressureplate (WIP)
Browse files Browse the repository at this point in the history
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
Phazorknight committed Apr 10, 2024
1 parent 76da194 commit fd4ab51
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 35 deletions.
91 changes: 91 additions & 0 deletions COGITO/CogitoObjects/Cogito_Pressureplate.gd
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()
66 changes: 66 additions & 0 deletions COGITO/CogitoObjects/Cogito_Pressureplate.tscn
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"]
8 changes: 4 additions & 4 deletions COGITO/DemoScenes/COGITO_01_Demo.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ script = ExtResource("16_fg1wi")
inventory_item = ExtResource("17_nl6sa")
quantity = 2

[sub_resource type="Resource" id="Resource_k3oka"]
[sub_resource type="Resource" id="Resource_jh2bj"]
resource_local_to_scene = true
script = ExtResource("2_chxar")
inventory_slots = Array[ExtResource("16_fg1wi")]([SubResource("Resource_v7b11"), SubResource("Resource_eku8j"), null, null])
Expand Down Expand Up @@ -348,7 +348,7 @@ size = Vector3(1.5, 0.01, 1.5)
[sub_resource type="BoxShape3D" id="BoxShape3D_ht4uj"]
size = Vector3(100, 3, 100)

[sub_resource type="Resource" id="Resource_7op24"]
[sub_resource type="Resource" id="Resource_hm5n6"]
resource_local_to_scene = true
script = ExtResource("2_chxar")
inventory_slots = Array[ExtResource("16_fg1wi")]([null, null, null, null, null, null, null, null])
Expand Down Expand Up @@ -1253,7 +1253,7 @@ transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107,
[node name="Chest" parent="INTERACTIVE_OBJECTS" groups=["external_inventory"] instance=ExtResource("14_d7sxi")]
transform = Transform3D(0.686504, 0, -0.727126, 0, 1, 0, 0.727126, 0, 0.686504, -4.38933, 0.0425703, 5.97176)
inventory_name = "Chest"
inventory_data = SubResource("Resource_k3oka")
inventory_data = SubResource("Resource_jh2bj")
uses_animation = true
open_animation = "open"

Expand Down Expand Up @@ -1613,7 +1613,7 @@ transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 2.1480
transform = Transform3D(-1, 0, 7.45058e-07, 0, 1, 0, -7.45058e-07, 0, -1, -7.5375, 0.905039, -3.30884)
pause_menu = NodePath("../TabMenu")
player_hud = NodePath("../Player_HUD")
inventory_data = SubResource("Resource_7op24")
inventory_data = SubResource("Resource_hm5n6")
step_height_camera_lerp = 1.5

[node name="Player_HUD" parent="." node_paths=PackedStringArray("player") instance=ExtResource("4_1ofwa")]
Expand Down
4 changes: 2 additions & 2 deletions COGITO/DemoScenes/COGITO_04_Demo_Lobby.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ volumetric_fog_temporal_reprojection_amount = 0.85
density = 0.04
albedo = Color(0.694118, 0.694118, 0.694118, 1)

[sub_resource type="Resource" id="Resource_5e8so"]
[sub_resource type="Resource" id="Resource_dp16f"]
resource_local_to_scene = true
script = ExtResource("4_0kggm")
inventory_slots = Array[Resource("res://COGITO/InventoryPD/CustomResources/InventorySlotPD.gd")]([null, null, null, null, null, null, null, null])
Expand Down Expand Up @@ -3290,7 +3290,7 @@ material = SubResource("FogMaterial_4avjx")
transform = Transform3D(-1, 0, 7.45058e-07, 0, 1, 0, -7.45058e-07, 0, -1, 3.03073, 0.905039, -17.9321)
pause_menu = NodePath("../PauseMenu")
player_hud = NodePath("../Player_HUD")
inventory_data = SubResource("Resource_5e8so")
inventory_data = SubResource("Resource_dp16f")
step_height_camera_lerp = 1.5

[node name="Player_HUD" parent="." node_paths=PackedStringArray("player") instance=ExtResource("5_to5tg")]
Expand Down
68 changes: 39 additions & 29 deletions COGITO/DemoScenes/COGITO_05_Demo_Laboratory.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=102 format=3 uid="uid://6hh7o77unixk"]
[gd_scene load_steps=104 format=3 uid="uid://6hh7o77unixk"]

[ext_resource type="Script" path="res://COGITO/SceneManagement/cogito_scene.gd" id="1_4dqq6"]
[ext_resource type="Texture2D" uid="uid://sdcljx8f5dhj" path="res://COGITO/Assets/hdris/kloofendal_48d_partly_cloudy_puresky_2k.hdr" id="1_ponqc"]
Expand Down Expand Up @@ -40,6 +40,8 @@
[ext_resource type="PackedScene" uid="uid://0fj068bj0csc" path="res://COGITO/PrefabScenes/Pickups/pickup_health_potion.tscn" id="37_0wxqc"]
[ext_resource type="PackedScene" uid="uid://sfypssn0rllo" path="res://COGITO/PrefabScenes/Pickups/pickup_stamina_extension.tscn" id="38_ayqrv"]
[ext_resource type="PackedScene" uid="uid://bekq2c16juwa1" path="res://COGITO/PrefabScenes/Pickups/pickup_dart.tscn" id="40_hi3jw"]
[ext_resource type="PackedScene" uid="uid://611llvxrvq88" path="res://COGITO/CogitoObjects/Cogito_Pressureplate.tscn" id="41_0755m"]
[ext_resource type="PackedScene" uid="uid://lsun1f1wjfxl" path="res://COGITO/PrefabScenes/ceiling_lamp.tscn" id="42_3rq3h"]

[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_wjbty"]
panorama = ExtResource("1_ponqc")
Expand Down Expand Up @@ -2708,6 +2710,33 @@ transform = Transform3D(-4.37114e-08, 0, 1, -1, -4.37114e-08, -4.37114e-08, 4.37
[node name="Pickup_LaserRifle" parent="SHOOTING_RANGE" instance=ExtResource("23_ex3ej")]
transform = Transform3D(-4.37114e-08, 0, 1, -1, -4.37114e-08, -4.37114e-08, 4.37114e-08, -1, 1.91069e-15, 3.22065, 0.821979, -15.3026)

[node name="Pickup_Pickaxe" parent="SHOOTING_RANGE" instance=ExtResource("29_ai41f")]
transform = Transform3D(0.995536, -0.0938573, -0.0099791, 0, 0.105726, -0.994395, 0.0943863, 0.989956, 0.105254, 1.44729, 0.86964, -11.7382)

[node name="HealthPotion" parent="SHOOTING_RANGE" instance=ExtResource("37_0wxqc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.393674, 1.21509, -11.2257)

[node name="HealthPotion2" parent="SHOOTING_RANGE" instance=ExtResource("37_0wxqc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.064918, 1.21509, -11.2257)

[node name="HealthPotion3" parent="SHOOTING_RANGE" instance=ExtResource("37_0wxqc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.607045, 1.21509, -11.2257)

[node name="Pickup_StaminaExtension" parent="SHOOTING_RANGE" instance=ExtResource("38_ayqrv")]
transform = Transform3D(0.980989, 0, 0.194063, 0, 1, 0, -0.194063, 0, 0.980989, -1.38741, 0.92349, -11.344)

[node name="Pickup_Dart" parent="SHOOTING_RANGE" instance=ExtResource("40_hi3jw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0614817, 1.00006, -11.7358)

[node name="Pickup_Dart2" parent="SHOOTING_RANGE" instance=ExtResource("40_hi3jw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.285636, 1.00006, -11.7358)

[node name="Pickup_Dart3" parent="SHOOTING_RANGE" instance=ExtResource("40_hi3jw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.665604, 1.00006, -11.7358)

[node name="Pickup_Dart4" parent="SHOOTING_RANGE" instance=ExtResource("40_hi3jw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.390677, 1.00006, -11.7358)

[node name="KSI_table_long" parent="SHOOTING_RANGE" instance=ExtResource("15_lsmut")]

[node name="Spawnzone_Targets" type="Area3D" parent="SHOOTING_RANGE" node_paths=PackedStringArray("spawn_area")]
Expand Down Expand Up @@ -2875,6 +2904,9 @@ transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, -9, 0,

[node name="KSI_steps_flat_corner" parent="MOVEMENT" instance=ExtResource("34_6q0uf")]

[node name="CarriableBox" parent="MOVEMENT" instance=ExtResource("35_hegwd")]
transform = Transform3D(0.952555, 0, 0.304366, 0, 1, 0, -0.304366, 0, 0.952555, -6.66945, 1, 4.34045)

[node name="VendingMachine" type="Node3D" parent="."]
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 8.2257, 2.23517e-08, -14.3489)

Expand Down Expand Up @@ -2917,9 +2949,6 @@ shape = SubResource("BoxShape3D_6s5b0")

[node name="SlidingDoor" parent="." instance=ExtResource("20_t5vwn")]

[node name="Pickup_Pickaxe" parent="." instance=ExtResource("29_ai41f")]
transform = Transform3D(0.995536, -0.0938573, -0.0099791, 0, 0.105726, -0.994395, 0.0943863, 0.989956, 0.105254, 1.44729, 0.86964, -11.7382)

[node name="barrel2" parent="." instance=ExtResource("31_c4s3c")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.26627, 0.0840335, -3.11525)

Expand All @@ -2929,35 +2958,16 @@ transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -7.248
[node name="HealZone" parent="." instance=ExtResource("36_fryka")]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -7.24998, 1.505, -0.72672)

[node name="HealthPotion" parent="." instance=ExtResource("37_0wxqc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.393674, 1.21509, -11.2257)

[node name="HealthPotion2" parent="." instance=ExtResource("37_0wxqc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.064918, 1.21509, -11.2257)

[node name="HealthPotion3" parent="." instance=ExtResource("37_0wxqc")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.607045, 1.21509, -11.2257)

[node name="Pickup_StaminaExtension" parent="." instance=ExtResource("38_ayqrv")]
transform = Transform3D(0.980989, 0, 0.194063, 0, 1, 0, -0.194063, 0, 0.980989, -1.38741, 0.92349, -11.344)
[node name="Cogito_Pressureplate" parent="." instance=ExtResource("41_0755m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0398592, 0)

[node name="CarriableBox" parent="." instance=ExtResource("35_hegwd")]
transform = Transform3D(0.952555, 0, 0.304366, 0, 1, 0, -0.304366, 0, 0.952555, -6.66945, 1, 4.34045)

[node name="Pickup_Dart" parent="." instance=ExtResource("40_hi3jw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0614817, 1.00006, -11.7358)

[node name="Pickup_Dart2" parent="." instance=ExtResource("40_hi3jw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.285636, 1.00006, -11.7358)

[node name="Pickup_Dart3" parent="." instance=ExtResource("40_hi3jw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.665604, 1.00006, -11.7358)

[node name="Pickup_Dart4" parent="." instance=ExtResource("40_hi3jw")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.390677, 1.00006, -11.7358)
[node name="CeilingLamp" parent="." instance=ExtResource("42_3rq3h")]
transform = Transform3D(-1, -6.18173e-08, 6.18173e-08, 0, 0.707107, 0.707107, -8.74228e-08, 0.707107, -0.707107, 0.441994, 1.78403, 1.3986)

[connection signal="pressed" from="SHOOTING_RANGE/KSI_console_spawn/GenericButton" to="SHOOTING_RANGE/Spawnzone_Targets" method="_on_generic_button_pressed"]
[connection signal="pressed" from="VendingMachine/GenericButton" to="VendingMachine/Spawnzone_VendingMachine" method="_on_generic_button_pressed"]
[connection signal="pressed" from="VendingMachine/GenericButton2" to="VendingMachine/Spawnzone_VendingMachine2" method="_on_generic_button_pressed"]
[connection signal="plate_activated" from="Cogito_Pressureplate" to="CeilingLamp" method="switch_on"]
[connection signal="plate_deactivated" from="Cogito_Pressureplate" to="CeilingLamp" method="switch_off"]

[editable path="MOVEMENT/Ladder"]
1 change: 1 addition & 0 deletions COGITO/DemoScenes/DemoPrefabs/barrel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ radius = 0.38

[node name="barrel" type="RigidBody3D"]
collision_layer = 3
mass = 10.0
script = ExtResource("1_p1u1m")

[node name="barrel" type="MeshInstance3D" parent="."]
Expand Down

0 comments on commit fd4ab51

Please sign in to comment.