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 = 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
MediumMake the flyer flap.
- Add
const FLAP = -300. - When
jumpis just pressed, setvelocity.ytoFLAP.
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
3Project: Flappy Flyer
Flyer GravityFlap the FlyerPractice on your own: Godot playground