Skip to content

Commit

Permalink
Merge pull request #188 from ac-arcana/main
Browse files Browse the repository at this point in the history
CarryableComponent Improvements
  • Loading branch information
ac-arcana authored May 7, 2024
2 parents 6e1171e + 774dee1 commit 8f5e164
Showing 1 changed file with 12 additions and 6 deletions.
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)

0 comments on commit 8f5e164

Please sign in to comment.