#Can anyone help me with adding touch controls?

1 messages · Page 1 of 1 (latest)

left dune
#

So i was using an FPS template in Godot, it's called Quality First Person Controller v2 from the asset library. Sadly, this template doesn't support mobile controls, i've added a joystick and touch buttons to allow me crouch, jump, and sprint. Now the only thing i need help with is by adding a way to look around. Can anyone help add or teach me how to do that?

Here's the code from character.gd:

turbid pumice
left dune
turbid pumice
#

Oh, I think the issue is that you're checking if the Input.mouse_mode is MOUSE_MODE_CAPTURED, but when you run the project using a Mobile device, the Input.mouse_mode will always be MOUSE_MODE_VISIBLE
@left dune

turbid pumice
left dune
turbid pumice
left dune
#

I guess so, i've tried to code a way to look around using InputEventScreenDrag, it just doesn't work. Probably because of the template though

left dune
turbid pumice
left dune
#

I've added the inputs to the InputMap and stuff

turbid pumice
# left dune Yes, nothing's touched.

Remove the Input.mouse_mode == Input.MOUSE_MODE_CAPTURED from
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:

In the _unhandled_input function

left dune
#

Should i just give you the project files?

turbid pumice
# left dune Say i remove it, it leaves out errors. If i delete the entire function, it still...

Replace the _unhandled_input function from

func _unhandled_input(event : InputEvent):
	if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
		mouseInput.x += event.relative.x
		mouseInput.y += event.relative.y
	# Toggle debug menu
	elif event is InputEventKey:
		if event.is_released():
			# Where we're going, we don't need InputMap
			if event.keycode == 4194338: # F7
				$UserInterface/DebugPanel.visible = !$UserInterface/DebugPanel.visible

to

func _unhandled_input(event : InputEvent):
	if event is InputEventMouseMotion:
		mouseInput.x += event.relative.x
		mouseInput.y += event.relative.y
	# Toggle debug menu
	elif event is InputEventKey:
		if event.is_released():
			# Where we're going, we don't need InputMap
			if event.keycode == 4194338: # F7
				$UserInterface/DebugPanel.visible = !$UserInterface/DebugPanel.visible
left dune
left dune
#

Ok what you did was remove it but yeah it still doesn't work

#

Maybe i should just redo the entire thing from scratch now, would be a good idea

#

But let me know if you have anything else, thanks.

turbid pumice
# left dune But let me know if you have anything else, thanks.

In my project, my looking around code is just this:


const MIN_HEAD_ROTATION: float = deg_to_rad(-89.0)
const MAX_HEAD_ROTATION: float = deg_to_rad(89.0)
const SENS: float = 0.003

func _unhandled_input(event: InputEvent) -> void:
	if event is InputEventMouseMotion:
		rotate_y(-event.relative.x * SENS)
		head.rotate_x(-event.relative.y * SENS)
		head.rotation.x = clampf(head.rotation.x, MIN_HEAD_ROTATION, MAX_HEAD_ROTATION)
left dune
#

If you don't mind me borrowing your code?

#

Idk if it would work but yeah i'll check

turbid pumice
left dune