The player is constantly following the mouse position.
class_name Player extends Area2D
func _physics_process(delta):
if is_playing:
global_position = global_position.lerp(get_global_mouse_position(), delta * movement_speed)
This works with mobile too, but… If you for example tap level 1, when level 1 starts, the player moves to the last position tapped before the level started.
This was easy to solve on computer with get_viewport().warp_mouse() but that doesn’t work with mobile.
This is a mobile game, so the mouse should be secondary, rather than the way it is now.
How can I make the player follow the touch position instead?
How do you even get the global touch position?
That will only work when clicking once and even if it was taking a drag event into account, it is not taking movement speed into account but would be instantaneous.
I have an autoload / singleton called G (globals.gd), in which I have among other global methods, constants and variables:
func _input(event):
if event is InputEventScreenTouch:
if event.is_pressed():
touching += 1
else:
touching = max(0, touching - 1) # the screen could already be pressed when the level starts
Then I do:
if is_playing and G.touching == 0: # because of multi-touch
...