Skip to content

Commit

Permalink
fixed unfocus bug that were not setting to null the current interacta…
Browse files Browse the repository at this point in the history
…ble into the raycast interactor
  • Loading branch information
ninetailsrabbit committed Dec 29, 2024
1 parent f0500d7 commit 7bee026
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ func push_state_to_stack(state: MachineState) -> void:

func lock_state_machine():
process_mode = ProcessMode.PROCESS_MODE_DISABLED
locked = true


func unlock_state_machine():
process_mode = ProcessMode.PROCESS_MODE_INHERIT
process_mode = ProcessMode.PROCESS_MODE_INHERIT
locked = false


func _prepare_states(node: Node = self):
Expand Down
17 changes: 13 additions & 4 deletions components/interaction/3D/interactables/interactable_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func _ready() -> void:
unfocused.connect(on_unfocused)
canceled_interaction.connect(on_canceled_interaction)

times_interacted = 0


func activate() -> void:
priority = 3
Expand All @@ -86,7 +88,6 @@ func activate() -> void:
monitoring = false

can_be_interacted = true
times_interacted = 0


func deactivate() -> void:
Expand Down Expand Up @@ -142,8 +143,10 @@ func on_interacted() -> void:
if disable_after_interaction:
deactivate()

_remove_outline_shader()
GlobalGameEvents.interactable_interacted.emit(self)



func on_focused() -> void:
_apply_outline_shader()

Expand All @@ -154,8 +157,14 @@ func on_unfocused() -> void:
_remove_outline_shader()

GlobalGameEvents.interactable_unfocused.emit(self)



func on_canceled_interaction() -> void:
if times_interacted < number_of_times_can_be_interacted:
activate()

_remove_outline_shader()

GlobalGameEvents.interactable_canceled_interaction.emit(self)

#endregion
#endregion
16 changes: 5 additions & 11 deletions components/interaction/3D/interactors/raycast_interactor_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func cancel_interact(interactable: Interactable3D = current_interactable):
interacting = false
focused = false
enabled = true

current_interactable = null

interactable.canceled_interaction.emit()


Expand All @@ -59,20 +60,13 @@ func focus(interactable: Interactable3D):
focused = true

interactable.focused.emit()


func unfocus(interactable: Interactable3D = current_interactable):
if interactable and focused:
current_interactable = null
focused = false
interacting = false
enabled = true

interactable.unfocused.emit()


func on_canceled_interaction(_interactable: Interactable3D) -> void:
current_interactable = null
focused = false
interacting = false
enabled = true
interactable.unfocused.emit()
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@icon("res://components/motion/3D/first-person/controller/mechanics/camera_controller_3d.svg")
class_name CameraController3D extends Node3D

@export var actor: Node3D
@export var actor: FirstPersonController
@export var camera: Camera3D
## 0 Means the rotation on the Y-axis is not limited
@export_range(0, 360, 1, "degrees") var camera_vertical_limit = 89
Expand Down Expand Up @@ -131,7 +131,7 @@ func unlock() -> void:


func swing_head(delta: float) -> void:
if swing_head_enabled and actor.is_grounded:
if swing_head_enabled and actor.is_grounded and not actor.finite_state_machine.locked:
var direction = actor.motion_input.input_direction

if direction in VectorHelper.horizontal_directions_v2:
Expand All @@ -141,7 +141,7 @@ func swing_head(delta: float) -> void:


func headbob(delta: float) -> void:
if bob_enabled and actor.is_grounded:
if bob_enabled and actor.is_grounded and not actor.finite_state_machine.locked:

bob_index += bob_speed * delta

Expand Down

0 comments on commit 7bee026

Please sign in to comment.