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