All lessons
Lesson 02

Platformer Movement

Switch to a side view. Gravity pulls down constantly, and jumping only fights it for a moment.

Loading the game engine. This takes a moment the first time.

Platformer only

This is the first side-view lesson. Gravity is always pulling the player down. Jumping fights it for a moment, and then gravity wins again.

The scenes

UI node · 2D node · % unique name · .tscn instanced scene

platformer_movement.tscn
  • PlatformerMovement Node2D platformer_movement.gd
  • PlatformPlayer CharacterBody2D player.tscn
  • HUD CanvasLayer % hud.tscn
  • Floor StaticBody2D
  • CollisionShape2D
  • Visual ColorRect
  • LeftWall StaticBody2D
  • CollisionShape2D
  • RightWall StaticBody2D
  • CollisionShape2D
  • Platform1 StaticBody2D
  • CollisionShape2D
  • Visual ColorRect
  • Platform2 StaticBody2D
  • CollisionShape2D
  • Visual ColorRect
  • Platform3 StaticBody2D
  • CollisionShape2D
  • Visual ColorRect
  • GoalArea Area2D %
  • ColorRect
  • CollisionShape2D
hud.tscn
  • HUD CanvasLayer hud.gd
  • MarginContainer
  • MessageLabel Label %
  • HomeButton Button %
player.tscn
  • PlatformPlayer CharacterBody2D player.gd
  • Sprite2D
  • CollisionShape2D
extends Node2D

func _ready() -> void:
	# "_ready()" runs once, when the scene starts. Setup goes here.
	# GoalArea is the green zone at the top of the level. We put the name
	# "_on_goal_reached" inside ".connect()". That is the function Godot
	# runs when something touches it.
	%GoalArea.body_entered.connect(_on_goal_reached)

# "body" is whatever touched the goal zone.
func _on_goal_reached(body: Node2D) -> void:
	# "PlatformPlayer" is the class_name at the top of player.gd.
	if body is PlatformPlayer:
		# hud.gd connects to "goal_reached" and puts the win message on screen.
		GameEvents.goal_reached.emit()