Held object rotation

This commit is contained in:
Rob Kelly 2025-07-07 12:05:45 -06:00
parent 7f83fa6244
commit cd9e13e870
4 changed files with 39 additions and 4 deletions

View File

@ -60,6 +60,7 @@ ACTION_sneak,Sneak
ACTION_sprint,Sprint
ACTION_fire,"Fire equipped tool"
ACTION_interact,Interact
ACTION_rotate_object,"Rotate held object (hold)"
ACTION_switch_mode,"Tool mode switch"
ACTION_select_next_tool,"Select next tool"
ACTION_select_prev_tool,"Select previous tool"

1 keys en
60 ACTION_sprint Sprint
61 ACTION_fire Fire equipped tool
62 ACTION_interact Interact
63 ACTION_rotate_object Rotate held object (hold)
64 ACTION_switch_mode Tool mode switch
65 ACTION_select_next_tool Select next tool
66 ACTION_select_prev_tool Select previous tool

View File

@ -81,6 +81,8 @@ debug/enable_navigation_agent_debug=false
debug/enable_navigation_agent_debug.editor_runtime=true
debug/enable_debug_menu=false
debug/enable_debug_menu.debug=true
config/input/object_rotation_sensitivity_y=0.5
config/input/object_rotation_sensitivity_x=0.5
[global_group]
@ -148,7 +150,12 @@ interact={
}
switch_mode={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
rotate_object={
"deadzone": 0.2,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
select_next_tool={

View File

@ -11,6 +11,8 @@ var mouse_sensitivity_y: float
var mouse_acceleration: float
var invert_pitch: bool
var hold_to_sneak: bool
var object_rotation_sensitivity_x: float
var object_rotation_sensitivity_y: float
var enable_screen_shake: bool
var enable_head_bob: bool
@ -35,6 +37,12 @@ func _read_settings() -> void:
mouse_acceleration = ProjectSettings.get_setting("game/config/input/mouse_acceleration")
invert_pitch = ProjectSettings.get_setting("game/config/input/invert_pitch")
hold_to_sneak = ProjectSettings.get_setting("game/config/input/hold_to_sneak")
object_rotation_sensitivity_x = ProjectSettings.get_setting(
"game/config/input/object_rotation_sensitivity_x"
)
object_rotation_sensitivity_y = ProjectSettings.get_setting(
"game/config/input/object_rotation_sensitivity_y"
)
enable_screen_shake = ProjectSettings.get_setting(
"game/config/accessibility/enable_screen_shake"

View File

@ -4,6 +4,8 @@ class_name HoldComponent extends Node3D
signal held
signal dropped
const ROTATION_SCALE_FACTOR := 10.0 * TAU
## Held object position lerp acceleration.
@export var hold_accel := 20.0
@ -68,14 +70,31 @@ func throw() -> void:
drop()
func rotate_object(relative_motion: Vector2) -> void:
hold_point.rotate(
Vector3.UP,
relative_motion.x * GameSettings.object_rotation_sensitivity_x / ROTATION_SCALE_FACTOR
)
hold_point.rotate(
Vector3.RIGHT,
relative_motion.y * GameSettings.object_rotation_sensitivity_y / ROTATION_SCALE_FACTOR
)
func holding_object() -> bool:
return !!_held_object
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED and holding_object():
print(event)
var mouse_motion := event as InputEventMouseMotion
if (
mouse_motion
and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED
and holding_object()
and Input.is_action_pressed("rotate_object")
):
rotate_object(mouse_motion.relative)
get_viewport().set_input_as_handled()
func _process_hold_controls() -> void: