How can i shoot a bullet from a Position2d node?

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

HI, im trying to create a game where you shoot a bullet to destroy asteroids but i cannot for the life in me get the bullet to appear on screen. Im still pretty new to coding in general so i need all the help i can get!

:bust_in_silhouette: Reply From: Merlin1846

Set the bullets position to the position 2d.

var bullet = preload("res://bullet.tscn")
var bulletVelocity = 200

func shoot():
    var bulletInstance = bullet.instance()
    bulletInstance.position = $Position2D.position
    bulletInstance.velocity.x = bulletVelocity

But do note you do not need a position 2d. This is standard scene instanceing and you will use it a ton, from shooting bullets to spawning enemys and coins.

Merlin1846 | 2020-03-10 15:19

there is no velocity property for bulletInstance did I do something wrong?

Chasethegamer | 2020-03-11 03:59