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

CarryableComponent Improvements #188

Merged
merged 3 commits into from
May 7, 2024
Merged
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
18 changes: 12 additions & 6 deletions COGITO/Components/Interactions/CarryableComponent.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extends InteractionComponent
class_name CarryableComponent
class_name CogitoCarryableComponent

signal carry_state_changed(is_being_carried : bool)
signal thrown(impulse)

@export_group("Carriable Settings")
@export var pick_up_sound : AudioStream
Expand Down Expand Up @@ -49,16 +52,15 @@ func carry(_player_interaction_component:PlayerInteractionComponent):
hold()



func _physics_process(_delta):
if is_being_carried:
carry_position = player_interaction_component.get_interaction_raycast_tip(carry_distance_offset)
parent_object.set_linear_velocity((carry_position - parent_object.global_position) * carrying_velocity_multiplier)

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


func _on_body_entered(body):
if body.is_in_group("Player") and is_being_carried:
leave()
Expand All @@ -81,6 +83,7 @@ func hold():
audio_stream_player_3d.play()

is_being_carried = true
carry_state_changed.emit(is_being_carried)


func leave():
Expand All @@ -90,12 +93,15 @@ func leave():
player_interaction_component.stop_carrying()
player_interaction_component.interaction_raycast.remove_exception(parent_object)
is_being_carried = false
carry_state_changed.emit(is_being_carried)


func throw(power):
leave()
if drop_sound:
audio_stream_player_3d.stream = drop_sound
audio_stream_player_3d.play()
print(name, ": Throwing with impulse force ", player_interaction_component.Get_Look_Direction() * power)
parent_object.apply_central_impulse(player_interaction_component.Get_Look_Direction() * power)
var impulse = player_interaction_component.Get_Look_Direction() * power
print(name, ": Throwing with impulse force ", impulse)
parent_object.apply_central_impulse(impulse)
thrown.emit(impulse)