Attention | Topic was automatically imported from the old Question2Answer platform. | |
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
else:
velocity.x = 0
if Input.is_action_pressed("lompat"):
if on_ground == true:
velocity.y = jump_power
on_ground = false
else:
velocity.y = 0
velocity.y += gravity
if is_on_floor():
on_ground = true
else:
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