my shooting code freezes after the first shot

godot version 4.3

my code creates a perfect shot the first time but then freezes and slowly moves each time i click
here’s my code


extends CharacterBody2D

@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D

const SPEED = 300.0
var bulletSpeed = 0.01
var bullet = preload(“res://scenes/bullet.tscn”)
var pos = position
var t = 0.0
var allowed = true
var bulletDistance = 3
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D
@onready var timer: Timer = $Timer

func Shoot():
if allowed == true:
var bulletInstance = bullet.instantiate()
bulletInstance.position = get_global_position()
bulletInstance.rotation = collision_shape_2d.rotation
get_parent().add_child(bulletInstance)
bulletInstance.position = position.lerp(get_global_mouse_position() * bulletDistance, t)

func reload():
allowed = false
timer.start

func _physics_process(delta: float) → void:

t += delta * bulletSpeed


var directionX := Input.get_axis("WalkL", "WalkR")
var directionY := Input.get_axis("WalkU", "WalkD")
var input := Vector2(directionX, directionY)
	
position += input * SPEED * delta

if input == Vector2(1, 0):
	animated_sprite.play("WalkR")
elif input == Vector2(-1, 0):
	animated_sprite.play("WalkL")
elif input == Vector2(0, 1):
	animated_sprite.play("WalkD")
elif input == Vector2(0,-1):
	animated_sprite.play("WalkU")
	
if input == Vector2(0, 0):
	animated_sprite.play("Idle")

if Input.is_action_just_pressed("Shoot"):
	Shoot()
	
	
move_and_slide()

func _on_timer_reload():
allowed = true
allowed = true

thank you in advance

Is your bullet supposed to spawn on your character in the shoot function and then move towards the direction of the mouse?

If that’s the case I would just spawn the bullet at your character and let it look at the global_mouse_position via the look_at() function and setting the velocity of the bullet which would be a rigid body:

@export var bullet_spawn_position : Node 2D
var bulletScene : PackedScene2D = preload("res://scenes/bullet.tscn")
const bullet_force : float = 500

func shoot():
   if not allowed:
      return

   var bullet : RigidBody2D = bulletScene.instantiate()
   bullet.global_position = bullet_spawn_position.global_position
   get_tree().current_scene.add_child(bullet)
   bullet.look_at(get_global_mouse_position())
   bullet.apply_central_force(Vector2.new(bullet_force, 0))

Bullet script:

const time_alive : float = 5.0

func _ready():
   # destroy after 5 seconds
   await get_tree().create_timer(time_alive).timeout
   queue_free()

Yes, then I multiply the mouse position vector2 to make it go past and not end before it dissapear(that will be added later), this is how I am doing shooting, but if that causes the issue I’m welcome to changes

Hey I edited my message and added some code for you.

Thank you

If something doesn’t work or if you do have any other questions just ask.