Menu
CoddyTech

Flyer Gravity

Part of the Projects section of Coddy's Godot journey. Lesson 22 of 36.

The third project is a flappy flyer. A robot bird falls all the time and flaps up when you press Space. It has to fly through the gaps between pipes.

The scripts are flyer.gd, pipe.gd and main.gd. Start with gravity. Every physics frame, gravity adds to the flyer's downward speed, and the speed moves it:

velocity.y += GRAVITY * delta
position += velocity * delta

Gravity changes the speed, not the position, so the fall gets faster each frame. Every CharacterBody2D already has a velocity.

challenge icon

Challenge

Easy

Make the flyer fall.

  1. In flyer.gd, add const GRAVITY = 900.
  2. Every physics frame, add GRAVITY * delta to velocity.y, then move the flyer by velocity * delta.

Press Play: the flyer drops faster and faster. Then Check.

Try it yourself

extends CharacterBody2D

func _physics_process(delta):
	pass

All lessons in Projects

Practice on your own: Godot playground