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

Update the outdated "Click-and-move" example in the 2D movement tutorial #9427

Merged
merged 1 commit into from
Jun 4, 2024
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
12 changes: 8 additions & 4 deletions tutorials/2d/2d_movement.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ on the screen will cause the player to move to the target location.
var target = position

func _input(event):
if event.is_action_pressed("click"):
target = get_global_mouse_position()
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
target = get_global_mouse_position()

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

public override void _Input(InputEvent @event)
{
if (@event.IsActionPressed("click"))
if (@event is InputEventMouseButton eventMouseButton)
{
_target = GetGlobalMousePosition();
if (eventMouseButton.ButtonIndex == MouseButton.Left && eventMouseButton.Pressed)
{
_target = GetGlobalMousePosition();
}
}
}

Expand Down