Skip to content

Commit

Permalink
CarryableComponent: Manual rotating
Browse files Browse the repository at this point in the history
CarryableComponent:
- Added option to enable manual rotating while an object is being carried.
- This can be enabled/disabled per object.
- Uses `action_secondary` as the hold-to-rotate button
- When button is held, use WASD / left joystick to rotate (this was chosen to enable gamepad compatibility)

- To be improved: currently only uses a global rotation vector. This is fine for rotating around the Y axis, but the X axis changes depending on which way the player is facing.
  • Loading branch information
Phazorknight committed Dec 2, 2024
1 parent 1dbc98b commit 2821a4d
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 67 deletions.
1 change: 0 additions & 1 deletion addons/cogito/Assets/Shader/BlurShader.tres
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void fragment() {

}
"
graph_offset = Vector2(-2019.17, 217.761)
mode = 1
flags/light_only = false
nodes/fragment/0/position = Vector2(-760, 80)
Expand Down
29 changes: 29 additions & 0 deletions addons/cogito/Components/Interactions/CarryableComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ signal thrown(impulse)
@export var carrying_velocity_multiplier : float = 10
## Sets how far away the carried object needs to be from the carry_position before it gets dropped.
@export var drop_distance : float = 1.5
## Sets if object can be rotated while being carried
@export var enable_manual_rotating : bool = true
## How fast the object rotates (in degrees per second)
@export var rotation_speed : float = 2.0

@onready var audio_stream_player_3d = $AudioStreamPlayer3D
@onready var camera : Camera3D = get_viewport().get_camera_3d()

var parent_object
var is_being_carried : bool
var is_being_rotated : bool = false
var player_interaction_component : PlayerInteractionComponent
var carry_position : Vector3 #Position the carriable "floats towards".

Expand Down Expand Up @@ -58,10 +63,30 @@ func _physics_process(_delta):
carry_position = player_interaction_component.get_carryable_destination_point(carry_distance_offset)
parent_object.set_linear_velocity((carry_position - parent_object.global_position) * carrying_velocity_multiplier)

if enable_manual_rotating:
if enable_manual_rotating and Input.is_action_pressed("action_secondary"):
player_interaction_component.player.is_movement_paused = true
is_being_rotated = true
rotate_object(_delta)

# Resume player movement when input action is released
if is_being_rotated and Input.is_action_just_released("action_secondary"):
player_interaction_component.player.is_movement_paused = false

if(carry_position-parent_object.global_position).length() >= drop_distance:
leave()


func rotate_object(_delta):
var input_dir
input_dir = Input.get_vector("left", "right", "forward", "back")

if input_dir.length() > 0:
var rotation_vector: Vector3 = Vector3(input_dir.y, input_dir.x, 0)
print("Rotating object by")
parent_object.global_rotate(rotation_vector, deg_to_rad(rotation_speed) )


func _on_body_entered(body):
if body.is_in_group("Player") and is_being_carried:
leave()
Expand Down Expand Up @@ -89,6 +114,10 @@ func hold():


func leave():
# Making sure the player movement resumes when object is dropped while being rotated
if is_being_rotated:
player_interaction_component.player.is_movement_paused = false

if lock_rotation_when_carried:
parent_object.set_lock_rotation_enabled(false)
if player_interaction_component and is_instance_valid(player_interaction_component):
Expand Down
8 changes: 4 additions & 4 deletions addons/cogito/DemoScenes/COGITO_3_Lobby.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,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_nbadd"]
[sub_resource type="Resource" id="Resource_ln60k"]
resource_local_to_scene = true
script = ExtResource("4_0kggm")
grid = true
Expand Down Expand Up @@ -2427,7 +2427,7 @@ shadow_mesh = SubResource("ArrayMesh_3ecdw")
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_upcaa"]
data = PackedVector3Array(0.6928, 0.0903, -1.6, 0, 0.0903, -1.2, 0.6128, 0.0903, -0.88, 0.6128, 0.0903, -0.88, 0.7728, 0.0903, -0.88, 0.6928, 0.0903, -1.6, 0.7728, 0.0903, -0.88, 1.3856, 0.0903, -1.2, 0.6928, 0.0903, -1.6, 0.7728, 0.0903, -0.88, 0.7728, 0.0903, -0.72, 1.3856, 0.0903, -1.2, 0.6128, 0.0903, -0.72, 0.6128, 0.0903, -0.88, 0, 0.0903, -1.2, 0.6928, 0.0903, 0, 0.6128, 0.0903, -0.72, 0, 0.0903, -1.2, 0.6928, 0.0903, 0, 0.7728, 0.0903, -0.72, 0.6128, 0.0903, -0.72, 0, 0.0903, -0.4, 0.6928, 0.0903, 0, 0, 0.0903, -1.2, 0, 0.0903, -1.2, 0, 0.0903, -0.8, 0, 0.0903, -0.4, 0.6928, 0.0903, 0, 1.3856, 0.0903, -0.4, 0.7728, 0.0903, -0.72, 1.3856, 0.0903, -0.4, 1.3856, 0.0903, -1.2, 0.7728, 0.0903, -0.72, 1.3856, 0.0903, -0.4, 1.3856, 0.0903, -0.8, 1.3856, 0.0903, -1.2, 0.6928, 0.1935, 0, 0, 0.1935, -0.4, 0, 0.1935, -1.2, 0, 0.1935, -1.2, 0.6928, 0.1935, -1.6, 0.6928, 0.1935, 0, 0.6928, 0.1935, -1.6, 1.3856, 0.1935, -0.4, 0.6928, 0.1935, 0, 0.6928, 0.1935, -1.6, 1.3856, 0.1935, -1.2, 1.3856, 0.1935, -0.4, 0.6928, 0.1935, -1.6, 0.6928, 0.0903, -1.6, 1.3856, 0.0903, -1.2, 1.3856, 0.0903, -1.2, 1.3856, 0.1935, -1.2, 0.6928, 0.1935, -1.6, 1.3856, 0.0903, -0.8, 1.3856, 0.0903, -0.4, 1.3856, 0.1935, -0.4, 1.3856, 0.1935, -0.4, 1.3856, 0.1935, -1.2, 1.3856, 0.0903, -0.8, 1.3856, 0.1935, -1.2, 1.3856, 0.0903, -1.2, 1.3856, 0.0903, -0.8, 1.3856, 0.1935, -0.4, 1.3856, 0.0903, -0.4, 0.6928, 0.0903, 0, 0.6928, 0.0903, 0, 0.6928, 0.1935, 0, 1.3856, 0.1935, -0.4, 0.6928, 0.1935, 0, 0.6928, 0.0903, 0, 0, 0.0903, -0.4, 0, 0.0903, -0.4, 0, 0.1935, -0.4, 0.6928, 0.1935, 0, 0, 0.1935, -1.2, 0, 0.1935, -0.4, 0, 0.0903, -0.4, 0, 0.0903, -0.4, 0, 0.0903, -0.8, 0, 0.1935, -1.2, 0, 0.0903, -0.8, 0, 0.0903, -1.2, 0, 0.1935, -1.2, 0, 0.1935, -1.2, 0, 0.0903, -1.2, 0.6928, 0.0903, -1.6, 0.6928, 0.0903, -1.6, 0.6928, 0.1935, -1.6, 0, 0.1935, -1.2, 0.7728, 0.0903, -0.72, 0.7728, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.6128, 0.0903, -0.72, 0.7728, 0.0903, -0.72, 0.6128, 0.0903, -0.88, 0.6128, 0.0903, -0.72, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.88, 0.6128, 0.0903, -0.88, 0.6128, 0.0903, -0.88, 0.6128, -0.4, -0.88, 0.7728, -0.4, -0.88, 0.7728, -0.4, -0.88, 0.7728, 0.0903, -0.88, 0.6128, 0.0903, -0.88, 0.7728, -0.4, -0.88, 0.7728, -0.4, -0.72, 0.7728, 0.0903, -0.72, 0.7728, 0.0903, -0.72, 0.7728, 0.0903, -0.88, 0.7728, -0.4, -0.88, 0.8128, -0.4, -0.68, 0.8128, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.4, -0.68, 0.8128, -0.4, -0.68, 0.5728, -0.4, -0.92, 0.5728, -0.4, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.92, 0.5728, -0.4, -0.92, 0.8128, -0.44, -0.92, 0.8128, -0.44, -0.68, 0.8128, -0.4, -0.68, 0.8128, -0.4, -0.68, 0.8128, -0.4, -0.92, 0.8128, -0.44, -0.92, 0.5728, -0.4, -0.68, 0.5728, -0.4, -0.92, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.8128, -0.4, -0.68, 0.5728, -0.4, -0.68, 0.6128, -0.4, -0.72, 0.7728, -0.4, -0.72, 0.8128, -0.4, -0.68, 0.7728, -0.4, -0.72, 0.7728, -0.4, -0.88, 0.8128, -0.4, -0.68, 0.6128, -0.4, -0.88, 0.6128, -0.4, -0.72, 0.5728, -0.4, -0.92, 0.5728, -0.4, -0.92, 0.8128, -0.4, -0.92, 0.6128, -0.4, -0.88, 0.8128, -0.4, -0.92, 0.7728, -0.4, -0.88, 0.6128, -0.4, -0.88, 0.8128, -0.4, -0.92, 0.8128, -0.4, -0.68, 0.7728, -0.4, -0.88, 0.4928, -0.44, -1, 0.4928, -0.44, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.5, -1, 0.4928, -0.44, -1, 0.4928, -0.44, -1, 0.4928, -0.5, -1, 0.8928, -0.5, -1, 0.8928, -0.5, -1, 0.8928, -0.44, -1, 0.4928, -0.44, -1, 0.8928, -0.44, -0.6, 0.8928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.44, -0.6, 0.8928, -0.44, -0.6, 0.8928, -0.5, -1, 0.8928, -0.5, -0.6, 0.8928, -0.44, -0.6, 0.8928, -0.44, -0.6, 0.8928, -0.44, -1, 0.8928, -0.5, -1, 0.4928, -0.44, -0.6, 0.4928, -0.44, -1, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.8928, -0.44, -0.6, 0.4928, -0.44, -0.6, 0.5728, -0.44, -0.68, 0.8128, -0.44, -0.68, 0.8928, -0.44, -0.6, 0.8128, -0.44, -0.68, 0.8128, -0.44, -0.92, 0.8928, -0.44, -0.6, 0.5728, -0.44, -0.92, 0.5728, -0.44, -0.68, 0.4928, -0.44, -1, 0.4928, -0.44, -1, 0.8928, -0.44, -1, 0.5728, -0.44, -0.92, 0.8928, -0.44, -1, 0.8128, -0.44, -0.92, 0.5728, -0.44, -0.92, 0.8928, -0.44, -1, 0.8928, -0.44, -0.6, 0.8128, -0.44, -0.92, 0.9128, -0.54, -1.02, 0.4728, -0.54, -1.02, 0.4728, -0.54, -0.58, 0.4728, -0.54, -0.58, 0.9128, -0.54, -0.58, 0.9128, -0.54, -1.02, 0.4928, -0.5, -1, 0.4728, -0.54, -1.02, 0.9128, -0.54, -1.02, 0.9128, -0.54, -1.02, 0.8928, -0.5, -1, 0.4928, -0.5, -1, 0.9128, -0.54, -1.02, 0.9128, -0.54, -0.58, 0.8928, -0.5, -0.6, 0.8928, -0.5, -0.6, 0.8928, -0.5, -1, 0.9128, -0.54, -1.02, 0.8928, -0.5, -0.6, 0.9128, -0.54, -0.58, 0.4728, -0.54, -0.58, 0.4728, -0.54, -0.58, 0.4928, -0.5, -0.6, 0.8928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4728, -0.54, -0.58, 0.4728, -0.54, -1.02, 0.4728, -0.54, -1.02, 0.4928, -0.5, -1, 0.4928, -0.5, -0.6, 0.5728, -0.4, -0.92, 0.5728, -0.44, -0.92, 0.8128, -0.44, -0.92, 0.8128, -0.44, -0.92, 0.8128, -0.4, -0.92, 0.5728, -0.4, -0.92)

[sub_resource type="Resource" id="Resource_ovfr1"]
[sub_resource type="Resource" id="Resource_7q4nq"]
resource_local_to_scene = true
script = ExtResource("4_0kggm")
grid = true
Expand Down Expand Up @@ -3169,7 +3169,7 @@ material = SubResource("FogMaterial_4avjx")

[node name="Player" parent="." instance=ExtResource("3_mgle8")]
transform = Transform3D(-1, 0, 7.45058e-07, 0, 1, 0, -7.45058e-07, 0, -1, 3.03073, 0.905039, -17.9321)
inventory_data = SubResource("Resource_nbadd")
inventory_data = SubResource("Resource_ln60k")
step_height_camera_lerp = 1.5

[node name="QUESTS" type="Node3D" parent="."]
Expand Down Expand Up @@ -6993,7 +6993,7 @@ shape = SubResource("ConcavePolygonShape3D_upcaa")

[node name="kitchenFridgeContainer2" parent="BREAK_ROOM" instance=ExtResource("57_fdyfl")]
transform = Transform3D(-1, 0, -1.50996e-07, 0, 1, 0, 1.50996e-07, 0, -1, 3.65301, -4.84288e-08, 6.17191)
inventory_data = SubResource("Resource_ovfr1")
inventory_data = SubResource("Resource_7q4nq")

[node name="kitchenMicrowave2" parent="BREAK_ROOM" instance=ExtResource("61_1x4um")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 1.98491, 0.84, 6.39503)
Expand Down
4 changes: 2 additions & 2 deletions addons/cogito/DemoScenes/COGITO_4_Laboratory.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ volumetric_fog_ambient_inject = 0.1
volumetric_fog_sky_affect = 0.1
volumetric_fog_temporal_reprojection_amount = 0.85

[sub_resource type="Resource" id="Resource_cnpux"]
[sub_resource type="Resource" id="Resource_l4o4l"]
resource_local_to_scene = true
script = ExtResource("4_hlewe")
grid = true
Expand Down Expand Up @@ -901,7 +901,7 @@ environment = SubResource("Environment_obnk3")
[node name="Player" parent="." instance=ExtResource("2_7qwrr")]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 5.13854, 0.8, -5.43073)
inventory_data = SubResource("Resource_cnpux")
inventory_data = SubResource("Resource_l4o4l")
[node name="CONNECTOR_TO_LOBBY" type="Node3D" parent="."]
Expand Down
Loading

0 comments on commit 2821a4d

Please sign in to comment.