Hero: Run
Part of the Input and Movement section of Coddy's Godot journey. Lesson 23 of 28.
Over the next lessons you build a platformer hero, one step at a time. Each lesson adds to the script from the lesson before. The level has ground, a pit, a step and a high ledge with a flag.
The hero is a CharacterBody2D with a CollisionShape2D and a Look node for its drawing. The ground, the step and the ledge are StaticBody2D nodes.
Start with gravity and running:
velocity.y += gravity * delta
velocity.x = Input.get_axis("move_left", "move_right") * speed
move_and_slide()Run right into the pit and the hero falls out of the level. Later lessons fix that.
Challenge
EasyIn _physics_process, make the hero fall with gravity, run left and right at speed, and move with move_and_slide().
Try it yourself
extends CharacterBody2D
var speed = 220
var gravity = 1000
func _physics_process(delta):
pass
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Input and Movement
5Project: Platformer Hero
Hero: RunHero: JumpPractice on your own: Godot playground