breadwinner/scenes/player/input_controller_component.gd
Hellie-xd 0a764354ba did a shitton of refactoring.
still has bugs, but almost works like the original, but has much better
structure. still might have to change around a bit, but closing in to
the final form.
2026-08-09 03:24:28 +02:00

63 lines
2.1 KiB
GDScript

class_name InputController extends Node
@export var cursor_raycast: RayCast3D
@export var prompt: Control
@export var player: Player
@export var hold_position: Marker3D
var held_object: RigidBody3D = null
signal toggle_flashlight
signal stamina_reset
func _physics_process(_delta: float) -> void:
if not Console.toggled or not UiManager.in_game_menu.visible:
#handle grabbed object
if held_object != null:
var target_pos = hold_position.global_position
var current_pos = held_object.global_position
var direction = target_pos - current_pos
held_object.linear_velocity = direction * PlayerConsts.GRAB_POWER
var current_quat = held_object.global_transform.basis.get_rotation_quaternion()
var target_quat = hold_position.global_transform.basis.get_rotation_quaternion()
var delta_quat = target_quat * current_quat.inverse()
var angle = delta_quat.get_angle()
var axis = delta_quat.get_axis()
if angle > PI:
angle -= TAU
held_object.angular_velocity = axis * angle * PlayerConsts.GRAB_ROTATION_POWER
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("open_menu"):
UiManager.toggle_in_game_menu()
if !Console.toggled and not UiManager.in_game_menu.visible:
if Input.is_action_just_pressed("show_debug_menu"):
UiManager.toggle_debug_menu()
if Input.is_action_just_pressed("flashlight"):
toggle_flashlight.emit()
if Input.is_action_just_released("jump") or Input.is_action_just_released("sprint"):
stamina_reset.emit()
if Input.is_action_just_pressed("grab"):
if cursor_raycast.is_colliding():
var hit_object = cursor_raycast.get_collider()
if hit_object is RigidBody3D and hit_object.is_in_group("grabbable") or hit_object.is_in_group("equippable"):
held_object = hit_object
held_object.gravity_scale = 0.0
held_object.angular_damp = 5.0
prompt.visible = false
if Input.is_action_just_released("grab") and held_object != null:
held_object.gravity_scale = 1.0
held_object.angular_damp = 0.0
held_object = null
prompt.visible = true