Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions tutorials/2d/2d_movement.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}

Expand Down