on left mouse click, spawn a single instance of bullet towards mouse cursor

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Corbedo

i’ve figured out how to get the angle and position to where I want to spawn my bullet object relative to the players position.

What I want to be able to do is spawn the bullet object/scene while the lmb is held down and prevent further spawning of more bullet instances until the left mouse button is pressed again.

any help is appreciated!

extends KinematicBody2D

var movespeed : int = 100;
var bullet = preload(“res://Scenes/Bullet.tscn”);

func _physics_process(delta):
_player_direction();
_move_player();

func _process(delta):
_shooting();

func _player_direction():
look_at(get_global_mouse_position());
rotation_degrees = rotation_degrees + 90;

func _move_player():
var distance_to_mouse = get_global_mouse_position().distance_to(self.position);
var direction_to_mouse : Vector2 = Vector2();
direction_to_mouse = (get_global_mouse_position() - position).normalized();
if Input.is_action_pressed(“move”) == true && distance_to_mouse > 5:
move_and_slide(direction_to_mouse * movespeed);

func _shooting():
var is_shooting = true;
var bullet_instance = bullet.instance();
var spawn_location : Vector2 = position.direction_to(get_global_mouse_position())
var spawn_distance : int = 10

if Input.is_action_pressed("shoot"):
	print(spawn_location)
	get_tree().get_root().add_child(bullet_instance);
	bullet_instance.position = Vector2((position) + spawn_location*spawn_distance)
	
	print (spawn_distance)
else:
	is_shooting = false;
:bust_in_silhouette: Reply From: AlexTheRegent

Use Input.is_action_just_pressed instead of Input.is_action_pressed.