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 * deltaGravity changes the speed, not the position, so the fall gets faster each frame. Every CharacterBody2D already has a velocity.
Challenge
EasyMake the flyer fall.
- In
flyer.gd, addconst GRAVITY = 900. - Every physics frame, add
GRAVITY * deltatovelocity.y, then move the flyer byvelocity * 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
3Project: Flappy Flyer
Flyer GravityFlap the FlyerPractice on your own: Godot playground