Flap the Flyer
Part of the Projects section of Coddy's Godot journey. Lesson 20 of 33.
Space makes the flyer flap. A flap sets the speed to a fixed upward value, so every flap feels the same.
if Input.is_action_just_pressed("jump"):
velocity.y = FLAPWith FLAP at -300, the flyer goes up, slows down as gravity adds to its speed, then falls.
Use is_action_just_pressed, so one press is one flap. Put the flap between the gravity line and the move line. Then the move uses the new speed in the same frame.
Challenge
MediumAdd const FLAP = -300. When jump is just pressed, set velocity.y to FLAP.
Try it yourself
extends CharacterBody2D
const GRAVITY = 900
func _physics_process(delta):
velocity.y += GRAVITY * delta
position += velocity * delta
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