diff --git a/tutorials/2d/2d_movement.rst b/tutorials/2d/2d_movement.rst index 76c0f73ecd1..1f5da929bec 100644 --- a/tutorials/2d/2d_movement.rst +++ b/tutorials/2d/2d_movement.rst @@ -231,9 +231,9 @@ on the screen will cause the player to move to the target location. var target = position func _input(event): - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_LEFT and event.pressed: - target = get_global_mouse_position() + # Use is_action_pressed to only accept single taps as input instead of mouse drags. + if event.is_action_pressed(&"click"): + target = get_global_mouse_position() func _physics_process(delta): velocity = position.direction_to(target) * speed @@ -254,12 +254,10 @@ on the screen will cause the player to move to the target location. public override void _Input(InputEvent @event) { - if (@event is InputEventMouseButton eventMouseButton) + // Use IsActionPressed to only accept single taps as input instead of mouse drags. + if (@event.IsActionPressed("click")) { - if (eventMouseButton.ButtonIndex == MouseButton.Left && eventMouseButton.Pressed) - { - _target = GetGlobalMousePosition(); - } + _target = GetGlobalMousePosition(); } }