KinematicBody2D test_move method not detecting collision correctly

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

I’m having problem with collision detection using test_move, as seem in the gif.

GIF

The issue seem to be solved when I add 0.1 to rel_vec.x, this can too be seem on the gif, the collision with the right wall is using the vector with added value, and the left is not.

The const player.JUMP_CORNER_CORRECTION is 8, the same size of a tile.

Am I using the function wrongly?

Here’s the code:

extends "res://characters/player/states/motion/motion.gd"

const HIGH_JUMP_FORCE = -180

func enter():
	player.velocity.y = HIGH_JUMP_FORCE

func update(delta: float):
	var input_dir = player.get_input_direction()

	_handle_horizontal_accel(input_dir.x, delta)
	player.flip_character(input_dir.x)

	# Half gravity jump peak
	if (player.velocity.y < player.JUMP_PEAK_THRESHOLD):
		player.apply_gravity(delta)
		add_trail_point()
	else:
		player.apply_gravity(delta, player.JUMP_PEAK_GRAVITY_SCALE)
		add_trail_point(Color.teal)

	var delta_y = player.velocity.y * delta
	if (player.velocity.y < 0 && player.test_move(player.global_transform, Vector2(0, delta_y))):
		_correct_jump_corner(player.JUMP_CORNER_CORRECTION, input_dir.x, delta_y)

	player.move(player.velocity, false)

func _correct_jump_corner(amount: int, dir: float, delta: float):
	if (dir >= 0):
		for i in range(1, amount + 1):
			if (!player.test_move(player.global_transform.translated(
				Vector2(i, 0)), Vector2(0.1, delta))):
				player.translate(Vector2(i, 0))
				return

	if (dir <= 0):
		for i in range(-1, -(amount + 1), -1):
			if (!player.test_move(player.global_transform.translated(
				Vector2(i, 0)), Vector2(0, delta))):
				player.translate(Vector2(i, 0))
				return