Skip to content

Commit

Permalink
Merge pull request #9835 from HubbleCommand/master
Browse files Browse the repository at this point in the history
2D movement overview - Click-and-move - use actions
  • Loading branch information
skyace65 authored Sep 5, 2024
2 parents f4a38c9 + 8a868a4 commit 8a922af
Showing 1 changed file with 6 additions and 8 deletions.
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

0 comments on commit 8a922af

Please sign in to comment.