How to make kinematicbody2d character walk up blocks?

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

I need my character to walk up blocks just like the way terraria does when you reach a block and you keep on walking you will go up then continue.

My code right now:

func _physics_process(delta):
	motion.y += GRAVITY*delta
	
	if Input.is_action_pressed('ui_left'):
		motion.x = -SPEED
	elif Input.is_action_pressed('ui_right'):
		motion.x = SPEED
	else:
		motion.x=0
	
	if is_on_floor():
		if Input.is_action_pressed("ui_up"):
			motion.y = JUMP_HEIGHT

	motion = move_and_slide(motion, UP)

I don’t want it to be a slope I want the character to move up then forward. How could I do this?