Making a flappy bird clone but cant add Gravity

Godot Version

Godot 4.2


Hello im making a flappy bird clone but im stuck on making the gravity at first i was trying to use kinetic body 2d then i reallesied it was renamed to charecterbody2d in godot 4.0 then i tryed to get the code for gravity buuut nothing worked its litrealy been 2 hours trying to get it working

What exactly are the issues you’re facing? Are you following a tutorial?

im not using a tutorial to make like a flappy bird game i know and i did things like the background animations etc… but i just want the code to add gravity nothing is working though im not sure why for example this code :extends CharacterBody2D

const JUMP_VELOCITY = -400.0
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)

func _physics_process(delta):
# Apply gravity
velocity.y += gravity * delta

# Handle Jump
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
    velocity.y = JUMP_VELOCITY

# Move and slide
move_and_slide(velocity, Vector2(0, -1))

im getting erros on this line move_and_slide(velocity, Vector2(0, -1))
Line 15:Too many arguments for “move_and_slide()” call. Expected at most 0 but received 2 1 and oh boy this is only 1 of the million codes i tried

In Godot 4.2, move_and_slide doesn’t take any arguments. Don’t pass it any values and it will just apply the velocity from velocity.

I will advice to actually check out tutorials to help you with it. There is no point banging your head on the wall if you don’t understand some of the core concepts.

This is an example of one I found on YouTube Flappy bird tutorial in 13 minutes

1 Like

Thats… 3 years ago
and im using godot 4
and i have everything fiqured out i just want the graviiiittyyy

I tried using rigid body 2d tooo extends RigidBody2D

var thrust = Vector2(0, -250)
var torque = 20000

func _integrate_forces(state):
if Input.is_action_pressed(“ui_up”):
var rotation_direction = 0
if Input.is_action_pressed(“ui_right”):
rotation_direction += 1
if Input.is_action_pressed(“ui_left”):
rotation_direction -= 1
state.apply_torque(rotation_direction * torque) this is my code but it still does not woork and im noot sure why

Ok nevemind i fixed it after a whole day bye

@lulezer Could you share the solution and mark it as solved? That way other people who have the same problem can benefit too :sparkles:

1 Like


dang uh so i was ggonna upload it but i finsished the game and all and forgot and now i lost the project… ops