Flyer Gravity
Part of the Projects section of Coddy's Godot journey. Lesson 19 of 33.
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 * deltaGravity changes the speed, not the position, so the fall gets faster each frame. Every CharacterBody2D already has a velocity.
Challenge
EasyIn flyer.gd, add const GRAVITY = 900. Every physics frame, add GRAVITY * delta to velocity.y, then move the flyer by velocity * delta.
Try it yourself
extends CharacterBody2D
func _physics_process(delta):
pass
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Projects
Practice on your own: Godot playground