How to wait for the next mouse input or control pressed?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By WayfairSalesRep

The game features a screen with planets on it and each planet can build space ships. I want to be able to click on a ship, select move, and then click on the planet to move the ship to.

Currently, each planet is an instantiated scene and the ships are children of those planet scenes. So what I am looking to do is basically reparent the ship nodes over to the other planet, but I need to get a “destination” to use as a parameter in the movement function.

The planets have a tool button over them that pulls up a menu with information. I’m not married to that design if something else works better, but the button interface could be potentially useful.

Any suggestions?

:bust_in_silhouette: Reply From: Wakatta

On your main_scene the one that houses your planets and ships you can use

var last_selection = null

func _on_selection(event, current_selection)
    if event.button_index == BUTTON_LEFT:
        if !event.is_pressed():
            if current_selection != last_selection:
                if last_selection == a_ship_node and current_selection == a_planet_node:
                   var planet = current_selection
                   planet.move_ship_toward(last_selection, event.position)
                last_selection = current_selection:

On your Planet scenes

func move_ship_toward(ship, position):
    var ship_position = ship.global_transform

    ship.global_transform = ship_position

func _ready():
    ship_node.connect("_gui_input", main_scene, "_on_selection", [self])
    connect("_gui_input", main_scene, "_on_selection", [self])

This example is written with 2D in mind
Ships and planets should be identifiable and have their own scrips
Position in move_ship_toward func is where you clicked but you can also use the planets position

The move_ship_toward func will not actualy move the ship just reparent it to the selected planet since i’m not aware of how your project is structured but when your ship reaches its destination you can call that funcion