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 physicsprocess(delta):
playerdirection();
moveplayer();
func _process(delta):
_shooting();
func playerdirection():
lookat(getglobalmouseposition());
rotationdegrees = rotationdegrees + 90;
func moveplayer():
var distancetomouse = getglobalmouseposition().distanceto(self.position);
var directiontomouse : Vector2 = Vector2();
directiontomouse = (getglobalmouseposition() - position).normalized();
if Input.isactionpressed("move") == true && distancetomouse > 5:
moveandslide(directionto_mouse * movespeed);
func shooting():
var isshooting = true;
var bulletinstance = bullet.instance();
var spawnlocation : Vector2 = position.directionto(getglobalmouseposition())
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;