Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first try implementing Shapecast for interaction detection. #277

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions COGITO/Components/PlayerInteractionComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ var device_id: int = -1 # Used for displaying correct input prompts depending o

## Raycast3D for interaction check.
@export var interaction_raycast: InteractionRayCast


var interactable: # Updated via signals from InteractionRayCast
set = _set_interactable

var carried_object = null: # Used for carryable handling.
set = _set_carried_object

var is_carrying: bool:
get: return carried_object != null
## Power with which object are thrown (opposed to being dropped)
Expand All @@ -35,6 +38,7 @@ var equipped_wieldable_node = null
var wieldable_was_on: bool = false
var is_wielding: bool:
get: return equipped_wieldable_item != null

var player_rid


Expand Down
52 changes: 52 additions & 0 deletions COGITO/Components/interaction_raycast.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[gd_scene load_steps=7 format=3 uid="uid://cbd2ojah4nun6"]

[ext_resource type="Script" path="res://COGITO/Scripts/interaction_raycast.gd" id="1_yf5t7"]

[sub_resource type="SphereShape3D" id="SphereShape3D_e2hxm"]
margin = 0.075
radius = 0.075

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_iac3b"]
transparency = 1
shading_mode = 0
albedo_color = Color(0.333333, 1, 0, 0.501961)

[sub_resource type="SphereMesh" id="SphereMesh_1juxf"]
material = SubResource("StandardMaterial3D_iac3b")
radius = 0.05
height = 0.1
radial_segments = 8
rings = 4

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_icisa"]
transparency = 1
shading_mode = 0
albedo_color = Color(1, 0, 0, 0.501961)

[sub_resource type="SphereMesh" id="SphereMesh_4320q"]
material = SubResource("StandardMaterial3D_icisa")
radius = 0.025
height = 0.05
radial_segments = 8
rings = 4

[node name="InteractionRaycast" type="RayCast3D"]
target_position = Vector3(0, 0, -2.5)
collision_mask = 3
script = ExtResource("1_yf5t7")

[node name="InteractionShapecast" type="ShapeCast3D" parent="."]
shape = SubResource("SphereShape3D_e2hxm")
target_position = Vector3(0, 0, -2.5)
margin = 0.08
max_results = 16
collision_mask = 3

[node name="ShapecastHotspot" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.5)

[node name="RaycastHighlighter" type="MeshInstance3D" parent="."]
mesh = SubResource("SphereMesh_1juxf")

[node name="TargetHighlighter" type="MeshInstance3D" parent="."]
mesh = SubResource("SphereMesh_4320q")
8 changes: 0 additions & 8 deletions COGITO/DemoScenes/COGITO_1_LegacyDemo.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,6 @@ material = ExtResource("1_lsda4")

[node name="Door_A" parent="INTERACTIVE_OBJECTS" instance=ExtResource("8_xabdk")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -14.9, 0, 9.2)
ignore_interaction_raycast = null
bidirectional_swing = true
open_rotation_deg = -95.0
closed_position = Vector3(-14.9, 0, 9.2)
Expand Down Expand Up @@ -1266,7 +1265,6 @@ hold_audio_stream = ExtResource("25_3nnou")
[node name="RampA" type="AnimatableBody3D" parent="INTERACTIVE_OBJECTS"]
transform = Transform3D(-0.0871558, -0.996195, 0, 0.996195, -0.0871558, 0, 0, 0, 1, -35, 0, 10)
script = ExtResource("23_rfav8")
ignore_interaction_raycast = null
use_z_axis = true
open_rotation_deg = 180.0
closed_rotation_deg = 95.0
Expand All @@ -1284,7 +1282,6 @@ shape = SubResource("BoxShape3D_rkvi0")
[node name="RampB" type="AnimatableBody3D" parent="INTERACTIVE_OBJECTS"]
transform = Transform3D(0.0871558, 0.996195, -1.50996e-07, 0.996195, -0.0871558, 0, -1.31602e-08, -1.50421e-07, -1, -43, 0, 10)
script = ExtResource("23_rfav8")
ignore_interaction_raycast = null
use_z_axis = true
open_rotation_deg = 180.0
closed_rotation_deg = 95.0
Expand All @@ -1301,7 +1298,6 @@ shape = SubResource("ConvexPolygonShape3D_hq8yc")

[node name="DoorLocked" parent="INTERACTIVE_OBJECTS" instance=ExtResource("8_xabdk")]
transform = Transform3D(1, 0, 1.06581e-14, 0, 1, 0, -1.06581e-14, 0, 1, -24.9, 0, 9.2)
ignore_interaction_raycast = null
is_locked = true
key = ExtResource("9_g1bqh")
key_hint = "Locked. Is there a key nearby?"
Expand Down Expand Up @@ -1359,7 +1355,6 @@ transform = Transform3D(0.90323, 0, 0.429156, 0, 1, 0, -0.429156, 0, 0.90323, -1
[node name="GateA" type="AnimatableBody3D" parent="INTERACTIVE_OBJECTS"]
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, -45, 0, 14.6)
script = ExtResource("23_rfav8")
ignore_interaction_raycast = null
open_rotation_deg = -80.0
closed_rotation_deg = -180.0
door_speed = 0.04
Expand All @@ -1377,7 +1372,6 @@ shape = SubResource("ConvexPolygonShape3D_qb88g")
[node name="GateB" type="AnimatableBody3D" parent="INTERACTIVE_OBJECTS"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -47, 0, 14.6)
script = ExtResource("23_rfav8")
ignore_interaction_raycast = null
open_rotation_deg = -100.0
door_speed = 0.02

Expand Down Expand Up @@ -1460,7 +1454,6 @@ skeleton = NodePath("../../..")
[node name="MovingPlattform" type="AnimatableBody3D" parent="INTERACTIVE_OBJECTS"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -42, -0.05, 17.5)
script = ExtResource("23_rfav8")
ignore_interaction_raycast = null
door_type = 1
closed_position = Vector3(-42, -0.05, 17.5)
open_position = Vector3(-7.8, -0.05, 15.8)
Expand Down Expand Up @@ -1711,7 +1704,6 @@ target_position = Vector3(0, 0, -1)
[node name="Door_for_Keypad" type="AnimatableBody3D" parent="."]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, -10.8, 0, 2.91)
script = ExtResource("23_rfav8")
ignore_interaction_raycast = null
is_locked = true
key_hint = "Key needed."
door_type = 1
Expand Down
9 changes: 0 additions & 9 deletions COGITO/DemoScenes/COGITO_3_Lobby.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6196,7 +6196,6 @@ collision_layer = 3
script = ExtResource("13_5x4ip")
open_sound = ExtResource("15_078vp")
close_sound = ExtResource("16_py2k0")
ignore_interaction_raycast = null
door_type = 1
open_position = Vector3(0, 0, 0.28)

Expand Down Expand Up @@ -6242,7 +6241,6 @@ collision_layer = 3
script = ExtResource("13_5x4ip")
open_sound = ExtResource("15_078vp")
close_sound = ExtResource("16_py2k0")
ignore_interaction_raycast = null
door_type = 1
closed_position = Vector3(0.625, 0.785, -0.03)
open_position = Vector3(0.625, 1.285, -0.03)
Expand Down Expand Up @@ -6313,14 +6311,12 @@ shape = SubResource("BoxShape3D_ecok4")

[node name="FrontDoor" parent="UPPER_OFFICE_CEO/WindowedDoor" index="0"]
unlock_sound = ExtResource("18_sk7n4")
ignore_interaction_raycast = null
is_locked = true
key = ExtResource("19_vxibd")

[node name="HiddenDoor" type="AnimatableBody3D" parent="UPPER_OFFICE_CEO"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 1, 0.0289998, -4.15)
script = ExtResource("13_5x4ip")
ignore_interaction_raycast = null
open_rotation_deg = 275.0
closed_rotation_deg = 180.0
door_speed = 0.2
Expand Down Expand Up @@ -6494,7 +6490,6 @@ transform = Transform3D(7.54979e-08, 0, -1, 0, 1, 0, 1, 0, 7.54979e-08, -3.04332

[node name="FrontDoor" parent="ARCHIVE/ArchiveDoor" index="0"]
interaction_text_when_locked = "Locked."
ignore_interaction_raycast = null
is_locked = true

[node name="Wall81" type="StaticBody3D" parent="ARCHIVE"]
Expand Down Expand Up @@ -6882,7 +6877,6 @@ transform = Transform3D(1, 0, 1.19209e-07, 0, 1, 0, -1.19209e-07, 0, 1, -5.92048

[node name="FrontDoor" parent="MEETING_ROOM/ConferenceDoor" index="0"]
interaction_text_when_locked = "Locked."
ignore_interaction_raycast = null

[node name="CSGPolygon3D" type="CSGPolygon3D" parent="MEETING_ROOM"]
transform = Transform3D(1, 0, -7.10543e-15, 0, 1, 0, 7.10543e-15, 0, 1, -7.26615, 0, -20.9217)
Expand Down Expand Up @@ -7263,7 +7257,6 @@ collision_layer = 3
script = ExtResource("13_5x4ip")
open_sound = ExtResource("49_uekwd")
close_sound = ExtResource("50_air2v")
ignore_interaction_raycast = null
open_rotation_deg = 95.0

[node name="door" type="MeshInstance3D" parent="BATHROOM_STALL2/wallDoorway2/DoorBasic/Door"]
Expand Down Expand Up @@ -7331,7 +7324,6 @@ shape = SubResource("ConvexPolygonShape3D_3vij5")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.4688, -2.57192, -1.98452)
collision_layer = 3
script = ExtResource("13_5x4ip")
ignore_interaction_raycast = null
open_rotation_deg = 92.0

[node name="paneling" type="MeshInstance3D" parent="BATHROOM_STALL2/DuctDoor"]
Expand Down Expand Up @@ -7774,7 +7766,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.57, 0, -20)
collision_layer = 3
script = ExtResource("13_5x4ip")
rattle_sound = ExtResource("65_cw5kp")
ignore_interaction_raycast = null
is_locked = true
key_hint = "I should look around more."
open_rotation_deg = 95.0
Expand Down
7 changes: 2 additions & 5 deletions COGITO/Enemies/cogito_basic_enemy.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[ext_resource type="Script" path="res://COGITO/DynamicFootstepSystem/Scripts/footstep_surface_detector.gd" id="13_mhpd1"]
[ext_resource type="AudioStream" uid="uid://dc03jiw2a6y3j" path="res://COGITO/DynamicFootstepSystem/FootstepProfiles/generic_footstep_profile.tres" id="14_kpkpk"]
[ext_resource type="Resource" uid="uid://ca0q2t6w08ubh" path="res://COGITO/DynamicFootstepSystem/FootstepMaterialLibrary/sample_footstep_material_library.tres" id="15_vx81w"]
[ext_resource type="Script" path="res://COGITO/Scripts/interaction_raycast.gd" id="17_x20mi"]
[ext_resource type="PackedScene" uid="uid://cbd2ojah4nun6" path="res://COGITO/Components/interaction_raycast.tscn" id="17_0qkwj"]

[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_p3jhp"]
height = 1.8
Expand Down Expand Up @@ -136,11 +136,8 @@ footstep_material_library = ExtResource("15_vx81w")
generic_fallback_landing_profile = ExtResource("14_kpkpk")
landing_material_library = ExtResource("15_vx81w")

[node name="InteractionRaycast" type="RayCast3D" parent="."]
[node name="InteractionRaycast" parent="." instance=ExtResource("17_0qkwj")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
target_position = Vector3(0, 0, -2.5)
collision_mask = 3
script = ExtResource("17_x20mi")

[connection signal="object_detected" from="SecurityCamera" to="." method="switch_to_chasing"]
[connection signal="object_no_longer_detected" from="SecurityCamera" to="." method="switch_to_patrolling"]
Expand Down
2 changes: 2 additions & 0 deletions COGITO/InventoryPD/Items/Cogito_Flashlight.tres
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ name = "Flashlight"
description = "Eats batteries like it's its job."
icon = ExtResource("1_f43pq")
is_stackable = false
is_droppable = true
stack_size = 0
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_flashlight.tscn"
hint_text_on_use = ""
item_size = Vector2(1, 1)
sound_pickup = ExtResource("3_f88a5")
3 changes: 3 additions & 0 deletions COGITO/InventoryPD/Items/Cogito_StaminaExtension.tres
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ script = ExtResource("3_vpu4k")
attribute_name = "stamina"
attribute_change_amount = 25.0
value_to_change = 1
consumable_effects = Array[Resource("res://COGITO/InventoryPD/CustomResources/ConsumableEffect.gd")]([])
name = "Stamina Extension"
description = "Drinking this permanently increases your maximum stamina."
icon = ExtResource("2_ylptx")
is_stackable = true
is_droppable = true
stack_size = 5
drop_scene = "res://COGITO/PackedScenes/Pickups/pickup_stamina_extension.tscn"
hint_icon_on_use = ExtResource("1_1g5jd")
hint_text_on_use = "Max stamina increased by 25."
item_size = Vector2(1, 1)
sound_use = ExtResource("4_obcds")
sound_pickup = ExtResource("4_3code")
4 changes: 2 additions & 2 deletions COGITO/PackedScenes/Pickups/pickup_dart.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ metallic = 1.0
height = 0.28
radius = 0.05

[sub_resource type="Resource" id="Resource_0ux3y"]
[sub_resource type="Resource" id="Resource_yhike"]
resource_local_to_scene = true
script = ExtResource("4_qk8k6")
inventory_item = ExtResource("3_ohc35")
Expand Down Expand Up @@ -116,7 +116,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.14, 0)
shape = SubResource("CylinderShape3D_xbicr")

[node name="PickupComponent" parent="." instance=ExtResource("2_u01ym")]
slot_data = SubResource("Resource_0ux3y")
slot_data = SubResource("Resource_yhike")

[node name="Lifespan" type="Timer" parent="."]

Expand Down
10 changes: 3 additions & 7 deletions COGITO/PackedScenes/cogito_player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
[ext_resource type="PackedScene" uid="uid://cetc123v5gnff" path="res://COGITO/Components/Attributes/SanityAttribute.tscn" id="7_27cpi"]
[ext_resource type="PackedScene" uid="uid://ce7bjv28uakxl" path="res://COGITO/Components/Attributes/StaminaAttribute.tscn" id="8_kodbk"]
[ext_resource type="PackedScene" uid="uid://cqgg1nng0vvbh" path="res://COGITO/Components/Attributes/HealthAttribute.tscn" id="9_ky5mf"]
[ext_resource type="PackedScene" uid="uid://cbd2ojah4nun6" path="res://COGITO/Components/interaction_raycast.tscn" id="10_2dndr"]
[ext_resource type="AnimationLibrary" uid="uid://cdchpsv104er2" path="res://COGITO/Assets/Animations/player_eyes.tres" id="10_tp6cj"]
[ext_resource type="Script" path="res://COGITO/Scripts/interaction_raycast.gd" id="11_miluh"]
[ext_resource type="AudioStream" uid="uid://up2hfhgq1qx6" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep00.ogg" id="12_ug3wt"]
[ext_resource type="AudioStream" uid="uid://crj07wq4oocwi" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep01.ogg" id="13_fyfhw"]
[ext_resource type="AudioStream" uid="uid://dewyukd562k37" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep02.ogg" id="14_opnk5"]
Expand Down Expand Up @@ -99,10 +99,7 @@ libraries = {
[node name="Camera" type="Camera3D" parent="Body/Neck/Head/Eyes"]
transform = Transform3D(1, 0, 0, 0, 1, 4.46638e-06, 0, -4.46638e-06, 1, 0, 0, 0)

[node name="InteractionRaycast" type="RayCast3D" parent="Body/Neck/Head/Eyes/Camera"]
target_position = Vector3(0, 0, -2.5)
collision_mask = 3
script = ExtResource("11_miluh")
[node name="InteractionRaycast" parent="Body/Neck/Head/Eyes/Camera" instance=ExtResource("10_2dndr")]

[node name="Wieldables" type="Node3D" parent="Body/Neck/Head"]
unique_name_in_owner = true
Expand All @@ -127,8 +124,7 @@ landing_material_library = ExtResource("19_pc36t")
wait_time = 0.5
one_shot = true

[node name="PlayerInteractionComponent" parent="." node_paths=PackedStringArray("interaction_raycast", "wieldable_container") instance=ExtResource("20_4f25o")]
interaction_raycast = NodePath("../Body/Neck/Head/Eyes/Camera/InteractionRaycast")
[node name="PlayerInteractionComponent" parent="." node_paths=PackedStringArray("wieldable_container") instance=ExtResource("20_4f25o")]
wieldable_container = NodePath("../Body/Neck/Head/Wieldables")

[node name="Player_HUD" parent="." node_paths=PackedStringArray("player") instance=ExtResource("21_j3p88")]
Expand Down
Loading