- Edited
Hi everyone. I'm trying to make a Twin Stick Shooter game, based on games like Nuclear Throne and Enter the Gungeon, but i have a big problem. In my game, for shooting, instead of using the mouse cursor, i use the arrow keys, the problem is: the bullets are working as a group, which means that when i shoot a bullet for the left direction, and then i shoot a new bullet for another direction, all the previous shooted bullets will change their direction based on the direction of the last bullet fired.
And i want to know how can i fix that. Sorry if my explanation wasn't good enough, english is not my mother language. Thanks in advance.
My Code:
BulletScene
extends Area2D
var spd = 10
onready var caminho = get_node("/root/Mundo/Player")
onready var caminho2 = get_node("/root/Mundo/Player/Position2D")
func _ready():
#Setando a rotação correta da Bala | OBS: Setei no ready por conta dele rodar as coisas bem antes
if (caminho2.position.x == 25 and caminho2.position.y == 0) || (caminho2.position.x == -25 and caminho2.position.y == 0):
$AnimatedSprite.rotation_degrees = 0
if (caminho2.position.x == 0 and caminho2.position.y == -30) || (caminho2.position.x == 0 and caminho2.position.y == 35):
$AnimatedSprite.rotation_degrees = 90
func _physics_process(delta):
#Funções para direcionar a basa [DIREÇÕES COMUNS]
if caminho.detectDirection == 1:
shootRight()
if caminho.detectDirection == 2:
shootLeft()
if caminho.detectDirection == 3:
shootUp()
if caminho.detectDirection == 4:
shootDown()
func shootRight():
position.x += spd
func shootLeft():
position.x -= spd
func shootUp():
position.y -= spd
func shootDown():
position.y += spd
Player Scene
var bullet = bulletPath.instance()
if Input.is_action_just_pressed("ui_right"):
detectDirection = 1
$Position2D.global_position.x = global_position.x + 25
$Position2D.global_position.y = global_position.y
bullet.position = $Position2D.global_position
get_tree().current_scene.add_child(bullet)
print($Position2D.position)
if Input.is_action_just_pressed("ui_left"):
detectDirection = 2
$Position2D.global_position.x = global_position.x + -25
$Position2D.global_position.y = global_position.y
bullet.position = $Position2D.global_position
get_tree().current_scene.add_child(bullet)
print($Position2D.position)
if Input.is_action_just_pressed("ui_up"):
detectDirection = 3
$Position2D.global_position.y = global_position.y - 30
$Position2D.global_position.x = global_position.x
bullet.position = $Position2D.global_position
get_tree().current_scene.add_child(bullet)
print($Position2D.position)
if Input.is_action_just_pressed("ui_down"):
detectDirection = 4
$Position2D.global_position.y = global_position.y + 35
$Position2D.global_position.x = global_position.x
bullet.position = $Position2D.global_position
get_tree().current_scene.add_child(bullet)
print($Position2D.position)