0 votes

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):

func _process(delta):

func playerdirection():
rotationdegrees = rotationdegrees + 90;

func moveplayer():
var distancetomouse = getglobalmouseposition().distanceto(self.position);
var directiontomouse : Vector2 = Vector2();
directiontomouse = (getglobalmouseposition() - position).normalized();
if Input.is
actionpressed("move") == true && distancetomouse > 5:
andslide(directionto_mouse * movespeed);

func shooting():
var is
shooting = true;
var bulletinstance = bullet.instance();
var spawn
location : Vector2 = position.directionto(getglobalmouseposition())
var spawn_distance : int = 10

if Input.is_action_pressed("shoot"):
    bullet_instance.position = Vector2((position) + spawn_location*spawn_distance)

    print (spawn_distance)
    is_shooting = false;
Godot version 3.2.3
in Engine by (12 points)

1 Answer

0 votes

Use Input.is_action_just_pressed instead of Input.is_action_pressed.

by (1,314 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.