Hitscan bullet trails

Godot 4.3
code of hitscan:
ifunc shoot():
if !animation_player.is_playing() or can_shoot == true:
match weapon:
weapons.SHOTGUN:
gun_sounds.play()
damage = 3
animation_player.play(“shoot”)
can_shoot = false
instance = bullet_trial.instantiate()
if shoot_position.is_colliding():
instance.init(gun_bar.global_position, shoot_position.get_collision_point()) #init is a function
if shoot_position.get_collider().is_in_group(“enemy”):
shoot_position.get_collider().hit(damage)
print(“fire”)
crosshair._hitmarker()
else:
print(aim_ray_end.global_position)
instance.init(gun_bar.global_position, aim_ray_end.global_position)
character_body_3d.get_parent().add_child(instance)

Code of bullet (where the function init is called)
func init(pos1, pos2):
var draw_mesh = ImmediateMesh.new()
mesh = draw_mesh
draw_mesh.surface_begin(Mesh.PRIMITIVE_LINES, material_override)
draw_mesh.surface_add_vertex(pos1)
draw_mesh.surface_add_vertex(pos2)
draw_mesh.surface_end()

Question

My bullets are being spawned in just fine however they seem to be lagging behind the player for some reason. I have done all I can to solve this problem but can’t find the issue.

Link to a video showing the problem https://youtu.be/QZzTwDLqMA0

Please format your code as Preformatted text with ```
As for the issue - how would you like it to look like instead? Because currently the trails just stay where they have been instantiated. You haven’t specified what’s your preferred way for it to look like. Any examples from other games that you’ve seen and liked?

Sorry for the incorrect format I swear it was properly done before hand it must be a problem on my end.

I want to have similar bullet trails like ultrakill’s piercer. So far the vfx for the bullets are fine but they seem to not be originating from the guns barrel but from the previous position of the guns barrel. For the point of the bullets first position I used the position of the raycast seen in the video. It doesn’t seem to be originating from the raycast but instead it seems to be lagging behind it. I would like to solve the issue of the bullet not matching up with the model.

For the gun model I have shirked the gun model down so that it fits into the players collision shape to prevent any clipping issues.