Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D movement overview - Click-and-move - use actions #9835

Merged
merged 8 commits into from
Sep 5, 2024
13 changes: 5 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"):
HubbleCommand marked this conversation as resolved.
Show resolved Hide resolved
target = get_global_mouse_position()

func _physics_process(delta):
velocity = position.direction_to(target) * speed
Expand All @@ -254,12 +254,9 @@ on the screen will cause the player to move to the target location.

public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseButton eventMouseButton)
if (Input.IsActionPressed("click"))
HubbleCommand marked this conversation as resolved.
Show resolved Hide resolved
{
if (eventMouseButton.ButtonIndex == MouseButton.Left && eventMouseButton.Pressed)
{
_target = GetGlobalMousePosition();
}
_target = GetGlobalMousePosition();
}
}

Expand Down