Mouse mode captured on touchscreen by a button

Godot Version

4.3

Question

Hi all, i see severall ways to use an onscreen controller. I tried virtual joypad and also built in controls in Godot where I can use also buttons for some input actions.

What I dont understand is if it is possible to virtual use mouse controls. Like looking around what I can do with my mouse but I also want that option for touchscreens on Android for example. Anyone know how to use that?

Hmm, you might be able to set Emulate mouse from touch in the project settings, but I expect that would interfere with other touch screen controls.

A better option might be to add joystick support to your camera controls and use a virtual joystick, which is something 3D Android games often do. Without knowing your camera logic I’m not 100% sure if this applies, but if you add some input actions in your project settings for camera up, down, left, and right, and then use Input.get_vector method to fill the same role as the mouse movement vector you should get something workable.

I use Racing cameras addon and there is a specific part about using the mouse after left click the mouse button when using the ORBIT camera:

func _on_unhandled_input(event: InputEvent) -> void:
	if Input.mouse_mode != Input.MOUSE_MODE_CAPTURED:
		return

	if event is InputEventMouseMotion:
		const DEG90 = PI/2

		var x_dir := -1 if invert_x_axis else 1
		var y_dir := -1 if invert_y_axis else 1
		_pivot1.rotate_y(-event.relative.x * x_dir * _shared.mouse_sensitivity)
		_pivot2.rotate_x(-event.relative.y * y_dir * _shared.mouse_sensitivity)
		_pivot2.rotation.x = clamp(_pivot2.rotation.x, -DEG90, DEG90)

	else:
		_check_mouse_wheel(event)


func _check_mouse_wheel(event:InputEvent) -> void:
	if event is InputEventMouseButton:
		var step := cam_speed
		if Input.is_key_pressed(KEY_SHIFT): step *= 2
		if Input.is_key_pressed(KEY_CTRL):  step /= 2

		if not invert_mouse_wheel:
			if   event.button_index == MOUSE_BUTTON_WHEEL_UP:   _cam_pos.z -= step
			elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN: _cam_pos.z += step
		else:
			if   event.button_index == MOUSE_BUTTON_WHEEL_UP:   _cam_pos.z += step
			elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN: _cam_pos.z -= step

		_cam_pos.z = clamp(_cam_pos.z, min_distance, max_distance)

So if I somewhere also create a function about the Input_get_vector part then maybe it is working on a touchscreen.

For steering the car I have a virtual controller what works nice. I thought that if I make a button with handles like a mouseclick then can use the second virtual controller for mouse wheel but that is not working.