Hello everyone ! I'm currently developing a 3d survival game but I'm having a problem.

Every time I shoot a weapon (create an instance of a bullet in 3d) the game slows down and but physic process increases, how can I fix this? thank you and wish you a good day !

bullet code:

extends RigidBody
class_name m9
const DEFAULT_SPEED: int = 100

func _ready():
	set_as_toplevel(true)

export var speed: int = DEFAULT_SPEED

func _process(delta):
	var f_direction = global_transform.basis.z.normalized()
	global_translate(f_direction * speed * delta)


func _on_Area_body_entered(body):
	queue_free()
func _on_Timer_timeout():
	queue_free()

    gun code

    extends Spatial
    
    const BULLET_SCENE_PATH: String = "res://Objects/Bullets/9mmBullet.tscn"
    const MAGAZINE_CAPACITY: int = 10
    
    var current_mag: int = 10
    var bullet = load(BULLET_SCENE_PATH)
    var can_shoot_bullet: bool = true
    var animation_player: AnimationPlayer
    
    func _ready() -> void:
    	animation_player = $"9mmMODEL/AnimationPlayer"
    
    func shoot() -> void:
    	if current_mag > 0:
    		if can_shoot_bullet:
    			var new_bullet = bullet.instance()
    			new_bullet.global_transform = $Muzle.global_transform
    			var scene_root = get_tree().get_root().get_children()[0]
    			scene_root.add_child(new_bullet)
    			animation_player.play("Shoot")
    			current_mag -= 1
    			can_shoot_bullet = false
    	elif current_mag == 0:
    		can_shoot_bullet = false
    		if Main.m9b > 0:
    			reload()
    
    func reload() -> void:
    	Main.m9b -= MAGAZINE_CAPACITY
    	current_mag += MAGAZINE_CAPACITY
    	animation_player.play("Reload")
    
    
    
    
    
    
    func _on_AnimationPlayer_animation_finished(anim_name):
    	if anim_name == "Reload":
    		can_shoot_bullet = true
    	if anim_name == "Shoot":
    		can_shoot_bullet = true

    Hi, please use code tags to make this easier to read, it's the </> symbol at the bottom.

    I want to read everything more clearly, but what strikes me is you don't seem to have a timer or anything restricting the amount of bullets coming out per second, I also don't see where your Input actions are.

      hi! Lethn to be able to shoot another ball the shooting animation must be finished (about 0.5s).

        Lethn Hi, please use code tags to make this easier to read

        I've edited the posts to format them.

        ike func _process(delta):

        _physics_process() is more appropriate for moving a game object.

        That may not solve the problem, but _physics_process() nominally runs 60 times/second, while _process() runs every idle frame, which can be much more frequent than 60 times/second.

        ike I highly recommend using a timer signal with a boolean instead of doing an animation check, see if that helps at all with the performance, you can still have a timer go off and fire at the appropriate time with the animation, that's how I've done it in my own code.