move_and_slide and jumping

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

I started using godot and try to make some tests.
But i’m blocked at this point :
I have a character (KinematicBody2D) and a tile map.
I can move him at the right or at the left, jump but i cant jump and move together.
When i try it go upper but dont move…
I think im not using correctly the move_and_slide but i dont know how to do…

here is my code :

    extends KinematicBody2D

# Declare member variables here. Examples:
const GRAVITY = 200
const WALK_SPEED = 200
var velocity = Vector2()
var sur_sol = false
var delai_jump=0
# var b = "text"

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

func get_input():
	velocity = Vector2()	
	if(Input.is_action_pressed("ui_right") == true):
		velocity.x += 1
	elif(Input.is_action_pressed("ui_left") == true):
		velocity.x -= 1
	if(Input.is_action_pressed("ui_down") == true):
		velocity.y += 1
	if(Input.is_action_pressed("ui_up") == true and is_on_floor()):

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
	if(delai_jump > 0):
		velocity.y -= 250
		delai_jump = delai_jump-1
	if(sur_sol == false):
		velocity.y += 12000*delta
	if(velocity.length() > 0):
		if(velocity.x < 0):
			$Sprite.flip_h = true
			velocity = velocity.normalized() * WALK_SPEED
		elif(velocity.x > 0):
			$Sprite.flip_h = false
			velocity = velocity.normalized() * WALK_SPEED
	move_and_slide(velocity, Vector2(0,-1))

Thanks for help

Hey, I’d recommend you watch a tutorial on how to make movement in Godot such as

Mariothedog | 2020-03-02 20:36