Dies ist eine alte Version des Dokuments!
Simple Platformer
Teaser
Kurz erklären was man in diesem Tutorial lernen kann
„In diesem Video lern ihr wie ihr ein eigenes Jump & Run in einer kostenlosen Gameengine baut.“
Voraussetzungen
Godot Installiertes Godot 4.x. Ich entwickle hier auf der aktuellen Version 4.5 aber das Tutorial ist auch auf jeden anderen 4.x Version durchführbar
Assets
Projekt erstellen
Level erstellen
Einstellungen Windows > Size > Width 480 Windows > Size > Height 270 Windows Width Override: 960 Windows Height Override: 540
Stretch > Mode Viewport Stretch > Aspect: keep
Rendering > Textures > Default Texture Filter: Nearest
Unter Input Map erstellen wir neue Input Aktionen Left, right, jump Für WASD-Steuerung und Cursor-Tasten
Player erstellen
- CharacterBody2D
- AnimatedSprite2D
- CollisionShape2D
Assets kopieren
Animationen erstellen
Profisorischen Boden im Level Staticbody2D Collisionshape2D > RectangleShape
Tile
Player Script
extends CharacterBody2D
const GRAVITY = 8.1
const SPEED = 50
const JUMP_VELOCITY = -150
func _physics_process(delta: float) -> void:
if Input.is_action_pressed("left"):
velocity.x = -SPEED
$AnimatedSprite2D.flip_h = true
$AnimatedSprite2D.play("run")
elif Input.is_action_pressed("right"):
velocity.x = SPEED
$AnimatedSprite2D.flip_h = false
$AnimatedSprite2D.play("run")
else:
velocity.x = 0
$AnimatedSprite2D.play("idle")
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
velocity.y += GRAVITY
move_and_slide()