Making jump smooth instead of teleporting

Godot Version

Godot_v4.2.2-stable_win64.exe

Question

I’m making a flappy bird game and I don’t know how to make the character jump smoothly instead of teleportning up. I’m new to godot (And game development in general) so any help would be appreciated :slight_smile:
Here is my code:

extends CharacterBody2D

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
const JUMP = -10000.0
const GRAVITY_MULTIPLIER = 20.0

func _physics_process(delta):
	velocity.y = gravity * delta * GRAVITY_MULTIPLIER
	if Input.is_action_just_pressed("Jump"):
		velocity.y += JUMP
	move_and_slide()

Adding the value to velocity is bad practice, just do velocity.y = JUMP

Other than that I dont see issues with the code so propably the JUMP value is just too high

I changed it to = instead of += but lowering the JUMP value only makes it teleport a shorter distance, but it’s still just teleporting

How did you set it to? I’d make it -400

At -400 the sprite barely moves on the screen

Why would you use a gravity multiplier of 20 though? That’s… A LOT.

I found the solution, it’s because I had to change the gravity velocity to += instead of =, that way it gradually accelerates downwards and it also fixed the jump so I can set it to a much lower value

This is the code that is working:

extends CharacterBody2D

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
const JUMP = -800.0
const GRAVITY_MULTIPLIER = 1.5

func _physics_process(delta):
	velocity.y += gravity * delta * GRAVITY_MULTIPLIER
	if Input.is_action_just_pressed("Jump"):
		velocity.y = JUMP
	move_and_slide()
1 Like

A gravity modifier at 1.5 is a lot better. :smiley:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.