This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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 physicsprocess(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)
Godot version godot engine 3.3.4
in Engine by (12 points)

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

+= or -=

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

1 Answer

0 votes

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.

by (450 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.