Menu
CoddyTech

Flap the Flyer

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

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 = FLAP

With 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 icon

Challenge

Medium

Make the flyer flap.

  1. Add const FLAP = -300.
  2. When jump is just pressed, set velocity.y to FLAP.

Press Play and tap Space: the flyer hops up, then falls. Then Check.

Try it yourself

extends CharacterBody2D

const GRAVITY = 900

func _physics_process(delta):
	velocity.y += GRAVITY * delta
	position += velocity * delta

All lessons in Projects

Practice on your own: Godot playground