Skip to content

Commit

Permalink
Carryable handling + Improved UI Scale
Browse files Browse the repository at this point in the history
Carryable handling:
- This has been cleaned up to check the reference better inside the PlayerInteractionComponent. - If a Carryable gets destroyed while carrying, the PlayerInteractionComponent cleans up the reference on the next interaction. Can probably still be improved a bit but shouldn't cause any crashes anymore.

UI Scaling:
- Changed the project window stretch mode to canvas_items which improves aliasing on the UI. It's not perfect but very usable.
  • Loading branch information
Phazorknight committed Mar 12, 2024
1 parent 6381b4d commit 003d035
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 120 deletions.
15 changes: 8 additions & 7 deletions COGITO/Components/Interactions/CarryableComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ var parent_object
var is_being_carried
var player_interaction_component
var carry_position : Vector3 #Position the carriable "floats towards".



func _ready():
parent_object = get_parent()
if parent_object.has_signal("body_entered"):
parent_object.body_entered.connect(_on_body_entered) #Connecting to body entered signal
else:
print(parent_object.name, ": CarriableComponent needs to be child to a RigidBody3D to work.")


func interact(_player_interaction_component):
player_interaction_component = _player_interaction_component

Expand All @@ -39,7 +41,7 @@ func interact(_player_interaction_component):
leave()
else:
hold()
player_interaction_component.started_carrying.emit(self)


func _physics_process(_delta):
if is_being_carried:
Expand All @@ -58,7 +60,7 @@ func _on_body_entered(body):
func hold():
if lock_rotation_when_carried:
parent_object.set_lock_rotation_enabled(true)
player_interaction_component.carried_object = self
player_interaction_component.start_carrying(self)
player_interaction_component.interaction_raycast.add_exception(parent_object)

# Play Pick up sound.
Expand All @@ -68,12 +70,12 @@ func hold():

is_being_carried = true


func leave():
if lock_rotation_when_carried:
parent_object.set_lock_rotation_enabled(false)
player_interaction_component.carried_object = null
player_interaction_component.stop_carrying()
player_interaction_component.interaction_raycast.remove_exception(parent_object)

is_being_carried = false


Expand All @@ -82,5 +84,4 @@ func throw(power):
if drop_sound:
audio_stream_player_3d.stream = drop_sound
audio_stream_player_3d.play()
parent_object.apply_central_impulse(player_interaction_component.look_vector * Vector3(power, power, power))

parent_object.apply_central_impulse(player_interaction_component.look_vector * Vector3(0, 0, power))
31 changes: 23 additions & 8 deletions COGITO/Components/PlayerInteractionComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var previous_interactable

## Node3D for carryables. Carryables will be pulled toward this position when being carried.
@export var carryable_position : Node3D
var is_carrying : bool = false
var carried_object = null #Used for carryable handling.
var throw_power : float = 1.5
var is_changing_wieldables : bool = false #Used to avoid any input acitons while wieldables are being swapped
Expand All @@ -41,9 +42,10 @@ func _ready():
#node.hide()
object_detected = false


func _process(_delta):
# when carrying object, disable all other prompts.
if carried_object:
if is_carrying:
pass
elif interaction_raycast.is_colliding():
interactable = interaction_raycast.get_collider()
Expand All @@ -59,9 +61,6 @@ func _process(_delta):
interactive_object_exit()
is_reset = true

# VECTOR 3 for where the player is currently looking
#var dir = (carryable_position.get_global_transform().origin - get_global_transform().origin).normalized()
#look_vector = dir


func interactive_object_enter(detected_object:Node3D):
Expand All @@ -79,9 +78,10 @@ func _input(event):
if event.is_action_pressed("interact"):

# if carrying an object, drop it.
if carried_object and carried_object.input_map_action == "interact":
if is_carrying and is_instance_valid(carried_object) and carried_object.input_map_action == "interact":
carried_object.throw(throw_power)
carried_object = null
elif is_carrying and !is_instance_valid(carried_object):
stop_carrying()

# Checks if raycast is hitting an interactable object that has an interaction for this input action.
if interaction_raycast.is_colliding():
Expand All @@ -97,9 +97,11 @@ func _input(event):

if event.is_action_pressed("interact2"):
# if carrying an object, drop it.
if carried_object and carried_object.input_map_action == "interact2":
if is_carrying and is_instance_valid(carried_object) and carried_object.input_map_action == "interact2":
carried_object.throw(throw_power)
carried_object = null
elif is_carrying and !is_instance_valid(carried_object):
stop_carrying()


# Checks if raycast is hitting an interactable object that has an interaction for this input action.
if interaction_raycast.is_colliding():
Expand Down Expand Up @@ -144,6 +146,19 @@ func get_interaction_raycast_tip(distance_offset : float) -> Vector3:
return destination_point


### Carryable Management
func start_carrying(_carried_object):
is_carrying = true
carried_object = _carried_object
started_carrying.emit(_carried_object)


func stop_carrying():
#carried_object.throw(throw_power)
is_carrying = false
carried_object = null



### Wieldable Management
func equip_wieldable(wieldable_item:WieldableItemPD):
Expand Down
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_e1jsb"]
[sub_resource type="Resource" id="Resource_1mbxj"]
resource_local_to_scene = true
script = ExtResource("2_chxar")
inventory_slots = Array[ExtResource("16_fg1wi")]([SubResource("Resource_wdflo"), SubResource("Resource_hpi7r"), 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_q4pan"]
[sub_resource type="Resource" id="Resource_j6n0w"]
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_e1jsb")
inventory_data = SubResource("Resource_1mbxj")
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_q4pan")
inventory_data = SubResource("Resource_j6n0w")
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 @@ -121,7 +121,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_unrwl"]
[sub_resource type="Resource" id="Resource_oqdwk"]
resource_local_to_scene = true
script = ExtResource("4_0kggm")
inventory_slots = Array[ExtResource("33_lg13i")]([null, null, null, null, null, null, null, null])
Expand Down Expand Up @@ -3222,7 +3222,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("../TabMenu")
player_hud = NodePath("../Player_HUD")
inventory_data = SubResource("Resource_unrwl")
inventory_data = SubResource("Resource_oqdwk")
step_height_camera_lerp = 1.5

[node name="Player_HUD" parent="." node_paths=PackedStringArray("player") instance=ExtResource("5_to5tg")]
Expand Down
3 changes: 2 additions & 1 deletion COGITO/DemoScenes/COGITO_05_Demo_Laboratory.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,8 @@ player_hud = NodePath("../Player_HUD")
[node name="Player_HUD" parent="." node_paths=PackedStringArray("player") instance=ExtResource("3_0c7yw")]
player = NodePath("../Player")

[node name="TabMenu" parent="." instance=ExtResource("4_vc32u")]
[node name="TabMenu" parent="." node_paths=PackedStringArray("nodes_to_focus") instance=ExtResource("4_vc32u")]
nodes_to_focus = [NodePath("Content/TabContainer/Game/VBoxContainer/ResumeGameButton"), NodePath("Content/TabContainer/Gameplay/ScrollContainer/VBoxContainer/InvertYAxisCheckButton"), null, NodePath("Content/TabContainer/Audio/ScrollContainer/VBoxContainer/MarginContainer/VBoxContainer/SFXVolumeSlider"), null]

[node name="CONNECTOR_TO_LOBBY" type="Node3D" parent="."]

Expand Down
8 changes: 4 additions & 4 deletions COGITO/PrefabScenes/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ footstep_material_library = ExtResource("18_q6u2l")
[node name="FootstepTimer" type="Timer" parent="."]
one_shot = true

[node name="JumpCooldownTimer" type="Timer" parent="."]
wait_time = 0.5
one_shot = true

[node name="PlayerInteractionComponent" parent="." node_paths=PackedStringArray("interaction_raycast", "carryable_position", "wieldable_nodes") instance=ExtResource("13_rawn6")]
interaction_raycast = NodePath("../Neck/Head/Eyes/Camera/InteractionRaycast")
carryable_position = NodePath("../CarryablePosition")
wieldable_nodes = [NodePath("../Neck/Head/Wieldables/Flashlight"), NodePath("../Neck/Head/Wieldables/Toy Pistol"), NodePath("../Neck/Head/Wieldables/Laser Rifle"), NodePath("../Neck/Head/Wieldables/Pickaxe")]

[node name="JumpCooldownTimer" type="Timer" parent="."]
wait_time = 0.5
one_shot = true

[connection signal="animation_finished" from="Neck/Head/Eyes/AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
[connection signal="timeout" from="SlidingTimer" to="." method="_on_sliding_timer_timeout"]
4 changes: 2 additions & 2 deletions COGITO/PrefabScenes/projectile_pistol.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ rings = 1
height = 0.25
radius = 0.05

[sub_resource type="Resource" id="Resource_omk7l"]
[sub_resource type="Resource" id="Resource_1smi0"]
resource_local_to_scene = true
script = ExtResource("4_tbkmk")
inventory_item = ExtResource("3_7etap")
Expand Down Expand Up @@ -60,6 +60,6 @@ wait_time = 30.0
autostart = true

[node name="PickupComponent" parent="." instance=ExtResource("4_acy7b")]
slot_data = SubResource("Resource_omk7l")
slot_data = SubResource("Resource_1smi0")

[connection signal="body_entered" from="." to="." method="_on_body_entered"]
1 change: 0 additions & 1 deletion COGITO/PrefabScenes/target_destructable.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ keep_compressed_buffer = true

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_arutm"]
resource_name = "target"
albedo_color = Color(1, 1, 1, 1)
albedo_texture = SubResource("PortableCompressedTexture2D_gi6as")
roughness = 0.5
texture_filter = 0
Expand Down
Loading

0 comments on commit 003d035

Please sign in to comment.