So, I am trying to make my first game, and its a galaga clone. However, I am running into some problems. I have 3 scenes, the player, the bullet, and the main scene.
The main scene just contains instances of the bullet and player
The player's tree is this:
Area2D(named Player)
CollisionShape2D
Sprite
The bullet's scene tree is this:
Area2D(Named Bullet)
Sprite
CollisionShape2D
VisibilityNotifier2D
Here is the script for the player:
extends Area2D
export var playerSpeed = 400
var screen_size
func _ready():
screen_size = get_viewport_rect().size
func _process(delta):
var Playervelocity = Vector2()
if Input.is_action_pressed("ui_right"):
Playervelocity.x += 1
if Input.is_action_pressed("ui_left"):
Playervelocity.x -= 1
position += Playervelocity * delta * playerSpeed
position.x = clamp(position.x, 0, screen_size.x)
Here is the bullet script:
extends Area2D
export var bulletSpeed = -500
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
func _process(delta):
position += Vector2(0.0, bulletSpeed * delta)
Here is the Main script:
extends Node2D
var Bullet = preload("res://Bullet.tscn")
func _process(delta):
if Input.is_action_just_pressed("ui_select"):
var bullet = Bullet.instance()
add_child(bullet)
$Bullet.position = $Player.position
So, my problem is that when I shoot multiple bullets, and I'm not at the spawn point for the player, the majority of the bullets shoot out from the player's spawn point and one shoots from the player, and every time you press space, the bullet that is shooting from the player teleports back to the player.