The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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.

in Engine by (20 points)

1 Answer

0 votes
Best answer

It should be

bullet.position

Instead of $Bullet which refers to one specific bullet

by (178 points)
selected by

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

Never, mind, capitols matter.... lol THNX

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 Frequently asked questions and 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 [email protected] with your username.