Godot Tutorial Space L3

This commit is contained in:
Torsten 2024-02-27 16:32:53 +01:00
parent d8b6323dee
commit 6a0d25a16a
2 changed files with 21 additions and 0 deletions

View file

@ -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()
```