I am making my first game, and running into some problems....

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Fizzleburn

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)

The bullet’s scene tree is this:

   Area2D(Named Bullet)

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

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()
		$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.

:bust_in_silhouette: Reply From: A112Studio

It should be


Instead of $Bullet which refers to one specific bullet

If i do that, then it gives me the error “Invalid index ‘position’ (on base: Packed Scene) with value of type ‘Vector2’”

Fizzleburn | 2020-05-20 20:15

Never, mind, capitols matter… lol THNX

Fizzleburn | 2020-05-20 20:20