How to combine jump and move right?

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

H!

I’m trying to combine a jump and a move to the right from the spot. But now it turns out only a micromovement to the right and a jump after that. Tell me, please, how to make the character jump forward and right (like a parabola) when you press the button up?

Godot 3.1

extends KinematicBody2D

var speed = 200
var gravity = 970
var ground = Vector2(0, -1)
var jump_power = 500

var velocity = Vector2()

func _physics_process(delta):
	
	velocity.y += gravity * delta
	velocity = move_and_slide(velocity, ground)
	
	if Input.is_action_just_pressed("ui_up") && is_on_floor():
		velocity.y = jump_power
        velocity.x = speed
:bust_in_silhouette: Reply From: Ingword

The guys suggested that I use the methods. And it all worked.

extends KinematicBody2D

var speed = 200
var gravity = 970
var ground = Vector2(0, -1)
var jump_power = 500

var velocity = Vector2()

func _physics_process(delta):
	
	# включаем гравитацию
	velocity.y += (gravity * delta)
	velocity = move_and_slide(velocity, ground)
	
	# прыжок вперед
	if Input.is_action_just_pressed("ui_up"):
		button_pressed()
	elif is_on_floor():
		velocity.x = 0

func button_pressed():
	if Input.is_action_pressed("ui_up") && is_on_floor():
		jump()
		move_right()
	pass

func move_right():
	velocity.x = speed
	pass

func jump():
	velocity.y = -jump_power
	pass