generated from krampus/template-godot4
Held object rotation
This commit is contained in:
parent
7f83fa6244
commit
cd9e13e870
@ -60,6 +60,7 @@ ACTION_sneak,Sneak
|
|||||||
ACTION_sprint,Sprint
|
ACTION_sprint,Sprint
|
||||||
ACTION_fire,"Fire equipped tool"
|
ACTION_fire,"Fire equipped tool"
|
||||||
ACTION_interact,Interact
|
ACTION_interact,Interact
|
||||||
|
ACTION_rotate_object,"Rotate held object (hold)"
|
||||||
ACTION_switch_mode,"Tool mode switch"
|
ACTION_switch_mode,"Tool mode switch"
|
||||||
ACTION_select_next_tool,"Select next tool"
|
ACTION_select_next_tool,"Select next tool"
|
||||||
ACTION_select_prev_tool,"Select previous tool"
|
ACTION_select_prev_tool,"Select previous tool"
|
||||||
|
|
@ -81,6 +81,8 @@ debug/enable_navigation_agent_debug=false
|
|||||||
debug/enable_navigation_agent_debug.editor_runtime=true
|
debug/enable_navigation_agent_debug.editor_runtime=true
|
||||||
debug/enable_debug_menu=false
|
debug/enable_debug_menu=false
|
||||||
debug/enable_debug_menu.debug=true
|
debug/enable_debug_menu.debug=true
|
||||||
|
config/input/object_rotation_sensitivity_y=0.5
|
||||||
|
config/input/object_rotation_sensitivity_x=0.5
|
||||||
|
|
||||||
[global_group]
|
[global_group]
|
||||||
|
|
||||||
@ -148,7 +150,12 @@ interact={
|
|||||||
}
|
}
|
||||||
switch_mode={
|
switch_mode={
|
||||||
"deadzone": 0.2,
|
"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={
|
select_next_tool={
|
||||||
|
@ -11,6 +11,8 @@ var mouse_sensitivity_y: float
|
|||||||
var mouse_acceleration: float
|
var mouse_acceleration: float
|
||||||
var invert_pitch: bool
|
var invert_pitch: bool
|
||||||
var hold_to_sneak: 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_screen_shake: bool
|
||||||
var enable_head_bob: bool
|
var enable_head_bob: bool
|
||||||
@ -35,6 +37,12 @@ func _read_settings() -> void:
|
|||||||
mouse_acceleration = ProjectSettings.get_setting("game/config/input/mouse_acceleration")
|
mouse_acceleration = ProjectSettings.get_setting("game/config/input/mouse_acceleration")
|
||||||
invert_pitch = ProjectSettings.get_setting("game/config/input/invert_pitch")
|
invert_pitch = ProjectSettings.get_setting("game/config/input/invert_pitch")
|
||||||
hold_to_sneak = ProjectSettings.get_setting("game/config/input/hold_to_sneak")
|
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(
|
enable_screen_shake = ProjectSettings.get_setting(
|
||||||
"game/config/accessibility/enable_screen_shake"
|
"game/config/accessibility/enable_screen_shake"
|
||||||
|
@ -4,6 +4,8 @@ class_name HoldComponent extends Node3D
|
|||||||
signal held
|
signal held
|
||||||
signal dropped
|
signal dropped
|
||||||
|
|
||||||
|
const ROTATION_SCALE_FACTOR := 10.0 * TAU
|
||||||
|
|
||||||
## Held object position lerp acceleration.
|
## Held object position lerp acceleration.
|
||||||
@export var hold_accel := 20.0
|
@export var hold_accel := 20.0
|
||||||
|
|
||||||
@ -68,14 +70,31 @@ func throw() -> void:
|
|||||||
drop()
|
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:
|
func holding_object() -> bool:
|
||||||
return !!_held_object
|
return !!_held_object
|
||||||
|
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if event is InputEventMouseMotion:
|
var mouse_motion := event as InputEventMouseMotion
|
||||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED and holding_object():
|
if (
|
||||||
print(event)
|
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:
|
func _process_hold_controls() -> void:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user