Fix mobile restart and swipe aiming while firing

This commit is contained in:
enne2
2026-10-11 00:13:06 +02:00
parent dee0b387ba
commit f246ede94f
5 changed files with 107 additions and 7 deletions
+27 -4
View File
@@ -15,7 +15,8 @@ const JOY_RADIUS := 92.0
const KNOB_RADIUS := 40.0
const BTN_RADIUS := 46.0
const BTN_FIRE_RADIUS := 62.0
const LOOK_SENSITIVITY := 1.7 # moltiplicatore del trascinamento nell'area di puntamento
const LOOK_TURN_RADIANS := PI # swipe largo quanto lo schermo = 180 gradi
const LOOK_VERTICAL_RATIO := 0.75
const EDGE := 24.0
const COLOR_BASE := Color(1, 1, 1, 0.09)
@@ -137,7 +138,7 @@ func _input(event: InputEvent) -> void:
elif event is InputEventScreenDrag:
index = event.index
pos = event.position
relative = event.relative
relative = event.screen_relative
is_drag = true
elif mouse_fallback and event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
index = MOUSE_INDEX
@@ -218,9 +219,31 @@ func _drag(index: int, pos: Vector2, relative: Vector2) -> void:
_joy_knob = (pos - _joy_origin).limit_length(JOY_RADIUS)
_apply_move()
_root.queue_redraw()
Role.LOOK:
Role.LOOK, Role.FIRE:
if player and player.has_method("apply_look"):
player.apply_look(relative * LOOK_SENSITIVITY)
player.apply_look(_look_delta(relative, _screen_width()))
## Stessa frazione di swipe = stessa rotazione, senza stretch o delta temporale.
static func _look_delta(relative: Vector2, screen_width: float) -> Vector2:
return relative * Vector2(1.0, LOOK_VERTICAL_RATIO) * LOOK_TURN_RADIANS / maxf(screen_width, 1.0) / 0.0025
func _screen_width() -> float:
return _size.x if DisplayServer.get_name() == "headless" else float(DisplayServer.window_get_size().x)
func release_all() -> void:
for index in _touches.keys():
_release(index)
for action in MOVE_ACTIONS + ["shoot", "grenade", "reload", "jump"]:
Input.action_release(action)
func _process(_dt: float) -> void:
if player and player.hp <= 0 and enabled:
release_all()
enabled = false
_root.hide()
func _exit_tree() -> void:
release_all()
## Traduce il vettore del joystick nelle azioni di movimento (analogiche).
func _apply_move() -> void: