Godot: Moving the player

In this tutorial, I will show you how to move a kinematic body using GDScript language.

extends KinematicBody2D


var speed = 200
const jump_power = -400
const gravity = 10
const Floor = Vector2(0,-1)
var on_ground = false
var velocity = Vector2()


func _physics_process(delta):
	
	if Input.is_action_pressed('ui_right'):
		velocity.x = speed
	elif Input.is_action_pressed('ui_left'):
		velocity.x = -speed
	else:
		velocity.x = 0
	
	if Input.is_action_pressed('ui_up'):
		if on_ground == true:
			velocity.y = jump_power
			on_ground = false
	velocity.y += gravity
	if is_on_floor():
		on_ground = true
	else:
		on_ground = false
		
	velocity = move_and_slide(velocity,Floor)