|Attention||Topic was automatically imported from the old Question2Answer platform.|
So I have a space ship. I want it to alternate firing between the left and right guns when I hold the mouse. I’ve messed with it a lot and have produced a few different behaviors but never the one I want. At one point I had it shooting and alternating correctly but only when I repeatedly clicked the LMB and not when I held it.
I started over and now I can tell the game knows when I am holding the button but there are different problems now. When I hold the LMB the bullet spawns and stays stuck to its spawn point until I release the button, then it flies as it should. However, when I fire another bullet, the old one disappears. I haven’t got around to adding a timer yet, as I can’t get the initial behavior I want yet. Some advice would be much appreciated. Keep in mind, I’m pretty much an absolute beginner!
[Here is a link to a recorded .gif that shows behavior.]
and here is my code.
#Start of player "action" controller. var Bullet = preload("res://Scenes/Bullet.tscn") var alt = 0 var LMB_held = false var bi = Bullet.instance() func _input(event): if event is InputEventMouseButton: if event.is_pressed(): set_process(true) func _process(delta): if Input.is_mouse_button_pressed(BUTTON_LEFT): alt == 0 bi.start($LeftGun.global_transform) get_parent().add_child(bi) alt+=1 if alt == 1: bi.start($RightGun.global_transform) get_parent().add_child(bi) alt-=1
Ignore the LMB_Held variable. It isn’t used right now, I was trying a few things and haven’t deleted it yet.