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
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”)
# 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
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.
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”):
state.apply_force(thrust.rotated(rotation))
else:
state.apply_force(Vector2())
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