KinematicBody collision against slope causes jumping

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

I have a KinematicBody with a capsule CollisionShape. I move it with the arrows and give it gravity. When it collides against a slope (ramp), it jumps, despite me casting the gravity in the direction of the collision normal. Any ideas?

extends KinematicBody

var speed = 600
var gravity = -9.8
var dir = Vector3()
var vel = Vector3()
var count = {"coll_ramp":0}
var norm = Vector3(1, 1, 1)

func _ready():
	pass
	
func _physics_process(delta):
	dir = Vector3(0, 0, 0)
	if Input.is_action_pressed("ui_left"):
		dir.x -= 1
	if Input.is_action_pressed("ui_right"):
		dir.x += 1
	if Input.is_action_pressed("ui_up"):
		dir.z -= 1
	if Input.is_action_pressed("ui_down"):
		dir.z += 1
	dir = dir.normalized()
	dir = dir * speed * delta
	if vel.y > 0:
		gravity = -20
	else:
		gravity = -30
	vel.y += gravity * delta
	vel.y *= norm.y
	vel.x = dir.x
	vel.z = dir.z
	vel = move_and_slide(vel, Vector3(0, 1, 0))
	norm = Vector3(1, 1, 1)
	if is_on_floor() and Input.is_action_just_pressed("jump"):
		vel.y = 10
	if get_slide_count() > 0:
		var coll = get_slide_collision(0)
		norm = coll.normal
		if coll.collider is RigidBody:
			coll.collider.apply_impulse(coll.position, -coll.normal * 0.25)