Created
March 3, 2025 04:14
-
-
Save lamarmarshall/f82d8e16465d62d14e0f56e55da561d7 to your computer and use it in GitHub Desktop.
godot, button, movement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Area2D | |
var direction : Vector2 = Vector2.ZERO | |
var speed: int = 350 | |
var can_move : bool = true | |
var min_positions: Vector2 = Vector2(20, 176) | |
var max_positions: Vector2 = Vector2(520, 730) | |
func _process(delta: float) -> void: | |
if can_move: | |
position += direction * speed * delta | |
position.x = clamp(position.x, min_positions.x, max_positions.x) | |
position.y = clamp(position.y, min_positions.y, max_positions.y) | |
func _on_up_button_pressed() -> void: | |
can_move = true | |
direction = Vector2.DOWN | |
func _on_down_button_pressed() -> void: | |
print("down") | |
can_move = true | |
direction = Vector2.UP | |
func _on_right_button_pressed() -> void: | |
print("right") | |
can_move = true | |
direction = Vector2.RIGHT | |
func _on_left_button_pressed() -> void: | |
print("left") | |
can_move = true | |
direction = Vector2.LEFT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment