This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Heya, i'm trying to make a space invader type game but when i try to spawn the bullet it doesn't spawn where i want it to, instead it spawns in a set location, i'm trying to get it to spawn ontop of the playership.
here's my code as of now.
Game:

  extends Node2D

var BulletScene = preload("res://PlayerBullet.tscn")
onready var ship = $PlayerShip

func spawn_bullet():
  var bullet = BulletScene.instance()
  bullet.global_position = $PlayerShip.position
  add_child(bullet)

func _process(delta):
    if Input.is_action_pressed("shoot"):
        spawn_bullet()

What do i do?

Godot version 3.5
in Engine by (14 points)

1 Answer

0 votes

place a Position 2D node on top of your ship and then in code change this:

func spawn_bullet():
  var bullet = BulletScene.instance()
  bullet.position = $Position2D.position
  add_child(bullet)
by (286 points)
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.