Collision happens a certain distance before it should

Godot Version

4.2.1

Question

Why are collision happening an extra distance before they should?

Context

Hi everyone, I’m trying to trace the trajectory a rigid body will follow, to do so I feed the same parameters that go into the rigid body to a Character Body and try to perform the same actions with the following code

extends Node3D
class_name TrajectoryCalculator

@export var new_point : PackedScene

func _ready() -> void:
	pass

func update_trajectory(posit: Vector3, dir: Vector3, speed: float, gravity: float, delta: float, bounce: float):
	var max_points = 500
	var pos: Vector3 = posit
	var vel = dir * speed
	for i in max_points:
		# Collision shape scaling to account for high speeds
		$CollisionTest/CollisionShape3D.scale = Vector3(1,1,1)*(1 + vel.length()/30.0)
		
		# Add new point to trajectory
		var point = new_point.instantiate()
		add_child(point)
		point.global_position = pos
		
		vel.y -= gravity * delta
		
		# Collision detection
		var collision = $CollisionTest.move_and_collide(vel * delta, false, true, true)
		var min_y = $CollisionTest/CollisionShape3D.scale.y * 0.159
		if collision and pos.y > min_y:
			print(pos)
			vel = vel.bounce(collision.get_normal()) * bounce
		elif collision and pos.y <= min_y:
			return pos
		
		# Linear damping
		var damp = ProjectSettings.get_setting("physics/3d/default_linear_damp")
		vel = vel * pow(1-damp,delta)
		
		pos += vel * delta
		$CollisionTest.global_position = pos
	return pos

The code is not the cleanest but it does work execept for one thing, the collisions are detected one meter above or to the side to where they should be, as if the collision shape was 1 meter larger in radius, here’s the collision points to show it(the radius of the spherical collison shape is 0.159m with a margin of 0.04m)

(4.732845, 1.196362, 25.53767)
(4.732845, 1.198811, 25.53767)
(4.732845, 1.196478, 25.53767)

Here is the more visual representation of the issue, I hope I’m explaining myself.
image

The collision shape is also perfectly centered on the CharacterBody3D and on its parent node so I’m really confused as to why this is happening. I think I encountered a similar problem some weeks ago but I cannot recall how I solved it so a little help would be very appreciated.

Thanks in advance!