From 6a0d25a16a6b9e29cf5d4ea15066de92406652f3 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 27 Feb 2024 16:32:53 +0100 Subject: [PATCH] Godot Tutorial Space L3 --- .../Player Input.md | 21 +++++++++++++++++++ ...e towards direction (setting rotation).md} | 0 2 files changed, 21 insertions(+) create mode 100644 MyObsidianVault/Godot_Training/2D/Tutorial Game - to space and beyond/Player Input.md rename MyObsidianVault/Godot_Training/2D/Tutorial Game - to space and beyond/{2024-02-17.md => turning image towards direction (setting rotation).md} (100%) diff --git a/MyObsidianVault/Godot_Training/2D/Tutorial Game - to space and beyond/Player Input.md b/MyObsidianVault/Godot_Training/2D/Tutorial Game - to space and beyond/Player Input.md new file mode 100644 index 0000000..028efba --- /dev/null +++ b/MyObsidianVault/Godot_Training/2D/Tutorial Game - to space and beyond/Player Input.md @@ -0,0 +1,21 @@ +https://school.gdquest.com/courses/learn_2d_gamedev_godot_4/to_space_and_beyond/taking_control + +```gdscript +extends Sprite2D +var direction := Vector2(0,0) +var max_speed := 600.0 +var velocity = Vector2(0, 0) + +func _process(delta: float) -> void: + + direction.x = Input.get_axis("move_left", "move_right") + direction.y = Input.get_axis("move_up", "move_down") + + if direction.length() > 1.0: + direction = direction.normalized() + + velocity = direction * max_speed + position += velocity * delta + if direction.length() > 0.0: + rotation = velocity.angle() +``` diff --git a/MyObsidianVault/Godot_Training/2D/Tutorial Game - to space and beyond/2024-02-17.md b/MyObsidianVault/Godot_Training/2D/Tutorial Game - to space and beyond/turning image towards direction (setting rotation).md similarity index 100% rename from MyObsidianVault/Godot_Training/2D/Tutorial Game - to space and beyond/2024-02-17.md rename to MyObsidianVault/Godot_Training/2D/Tutorial Game - to space and beyond/turning image towards direction (setting rotation).md