extends Control var pressed: bool = false var previous_position : Vector2 = Vector2.ZERO var speed : float = 0.04 func _gui_input(event: InputEvent) -> void: # Filter touch or drag events only. if event is not InputEventScreenTouch and event is not InputEventScreenDrag: return if event is InputEventScreenTouch: if event.is_pressed(): pressed = true else: pressed = false simulate_joystick_motion(JOY_AXIS_RIGHT_X, 0, 0) if pressed and event is InputEventScreenDrag: var delta_position : Vector2 = event.position - previous_position #print(delta_position) simulate_joystick_motion(JOY_AXIS_RIGHT_X, -delta_position.x * speed, 0) #simulate_joystick_motion(JOY_AXIS_RIGHT_Y, delta_position.y * speed, 0) # finally update the previous position previous_position = event.position func simulate_joystick_motion(axis: int, value: float, device_id: int = 0) -> void: var joystick_event = InputEventJoypadMotion.new() joystick_event.device = device_id joystick_event.axis = axis # Axis index (e.g., 0 for X-axis, 1 for Y-axis) joystick_event.axis_value = value # Value of the axis, typically between -1 and 1 Input.parse_input_event(joystick_event) # Process the event