Added touchscreen controls!
This commit is contained in:
@@ -22,6 +22,7 @@ var teleported_this_frame: bool = false # Flag to prevent position sync from ove
|
||||
|
||||
# Input device (for local multiplayer)
|
||||
var input_device: int = -1 # -1 for keyboard, 0+ for gamepad index
|
||||
var virtual_joystick_input: Vector2 = Vector2.ZERO # Virtual joystick input from mobile controls
|
||||
|
||||
# Interaction
|
||||
var held_object = null
|
||||
@@ -271,9 +272,8 @@ func _ready():
|
||||
|
||||
# Set up cone light blend mode, texture, initial rotation, and spread
|
||||
if cone_light:
|
||||
_create_cone_light_texture()
|
||||
_update_cone_light_rotation()
|
||||
_update_cone_light_spread()
|
||||
_update_cone_light_spread() # This calls _create_cone_light_texture()
|
||||
|
||||
# Wait before allowing RPCs to ensure player is fully spawned on all clients
|
||||
# This prevents "Node not found" errors when RPCs try to resolve node paths
|
||||
@@ -1056,10 +1056,26 @@ func _physics_process(delta):
|
||||
func _handle_input():
|
||||
var input_vector = Vector2.ZERO
|
||||
|
||||
if input_device == -1:
|
||||
# Check for virtual joystick input first (mobile/touchscreen)
|
||||
if virtual_joystick_input.length() > 0.01:
|
||||
input_vector = virtual_joystick_input
|
||||
elif input_device == -1:
|
||||
# Keyboard input
|
||||
input_vector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
|
||||
input_vector.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
|
||||
input_vector.x = max(
|
||||
Input.get_action_strength("move_right"),
|
||||
Input.get_action_strength("ui_right")
|
||||
) - max(
|
||||
Input.get_action_strength("move_left"),
|
||||
Input.get_action_strength("ui_left")
|
||||
)
|
||||
|
||||
input_vector.y = max(
|
||||
Input.get_action_strength("move_down"),
|
||||
Input.get_action_strength("ui_down")
|
||||
) - max(
|
||||
Input.get_action_strength("move_up"),
|
||||
Input.get_action_strength("ui_up")
|
||||
)
|
||||
else:
|
||||
# Gamepad input
|
||||
input_vector.x = Input.get_joy_axis(input_device, JOY_AXIS_LEFT_X)
|
||||
@@ -2252,8 +2268,18 @@ func _handle_struggle(delta):
|
||||
var input_dir = Vector2.ZERO
|
||||
|
||||
if input_device == -1: # Keyboard
|
||||
input_dir.x = Input.get_axis("move_left", "move_right")
|
||||
input_dir.y = Input.get_axis("move_up", "move_down")
|
||||
input_dir.x = clamp(
|
||||
Input.get_axis("move_left", "move_right")
|
||||
+ Input.get_axis("ui_left", "ui_right"),
|
||||
-1.0,
|
||||
1.0
|
||||
)
|
||||
input_dir.y = clamp(
|
||||
Input.get_axis("move_up", "move_down")
|
||||
+ Input.get_axis("ui_up", "ui_down"),
|
||||
-1.0,
|
||||
1.0
|
||||
)
|
||||
else: # Gamepad
|
||||
input_dir.x = Input.get_joy_axis(input_device, JOY_AXIS_LEFT_X)
|
||||
input_dir.y = Input.get_joy_axis(input_device, JOY_AXIS_LEFT_Y)
|
||||
|
||||
Reference in New Issue
Block a user