godot-shooter / commit
Hide the mouse and always follow it with the destination graphic.
World.gd | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/World.gd b/World.gd index 1c5de5c..b151944 100644 --- a/World.gd +++ b/World.gd @@ -7,6 +7,10 @@ var destination: Vector2 var is_destination_set = false func _ready() -> void: + # hide mouse + Input.mouse_mode = Input.MOUSE_MODE_HIDDEN + + # create enemies for n in enemy_count: add_new_enemy(true) @@ -31,11 +35,15 @@ func add_new_enemy(should_be_visible: bool = false) -> void: func _input(event: InputEvent) -> void: if event is InputEventScreenTouch: if event.pressed && !$Player.dead: - Utils.log("event position", event.position) - Utils.log("to_global(event.position)", to_global(event.position)) - Utils.log("player", $Player.position) var result = event.position + $Player.position - Vector2(500, 300) set_destination(result) + elif event is InputEventScreenDrag: + if !$Player.dead: + var result = event.position + $Player.position - Vector2(500, 300) + set_destination(result) + if event is InputEventMouseMotion: + var result = event.position + $Player.position - Vector2(500, 300) + set_destination(result) func _process(_delta: float) -> void: if Input.is_action_just_pressed("click") and !$Player.dead: @@ -52,15 +60,13 @@ func _process(_delta: float) -> void: $Destination.visible = true else: $Destination.visible = false - $Player.velocity = Vector2.ZERO func set_destination(pos: Vector2) -> void: - Utils.log("setting destination to ", pos) destination = pos is_destination_set = true $Destination.global_position = pos $Destination.visible = true - $Player. global_rotation = global_position.direction_to(get_global_mouse_position()).angle() + PI/2.0 + $Player. global_rotation = global_position.direction_to(pos).angle() + PI/2.0 func _on_Destination_body_entered(body: Node) -> void: if body == $Player: