Can you help me fix my code, my player gravity falling down too slow, its a 2d platform

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PurplesJack

extends KinematicBody2D

const speed = 200
const jump_power = -250
export (int) var gravity = 100
const FLOOR = Vector2(0, -1)

var velocity = Vector2()

var on_ground = false

func _physics_process(delta):

if Input.is_action_pressed("kanan"):
	velocity.x = speed
elif Input.is_action_pressed("kiri"):
	velocity.x = -speed
	velocity.x = 0
if Input.is_action_pressed("lompat"):
	if on_ground == true:
		velocity.y = jump_power
		on_ground = false
	velocity.y = 0
velocity.y += gravity

if is_on_floor():
	on_ground = true
	on_ground = false

velocity = move_and_slide(velocity, FLOOR)

Instead of setting the velocity, add/subtract to the velocity vector.

+= or -=

It will change your numbers around, but that should work better

MattMakingAGame | 2021-10-20 06:54

:bust_in_silhouette: Reply From: Pomelo

A simple awnser would be to change gravity to a higher number. dont know if thar is what you are asking. What i can see in your code, is that if you are not pressing “lompat” (what is lompat haha), then in every frame your velocity.y is set to 0. So even though you are adding the gravity every frame, you are also seeting it to cero.