#I can not for the life of my figure out how to attach bullets that I am spawning in to my gun.

1 messages · Page 1 of 1 (latest)

dapper shoal
#

I have a bullet scene with the sprite. I then have a spawner in a separate scene that is supposed to instance the bullet scene.

My player has a a child gun that rotates based on the mouse position. The gun has a marker 2D at the muzzle.

For the life of me I can't figure out how to attach the spawner to the marker 2D on the barrel of the gun.

Please help...been two days of banging my head. I am new to this.

dreamy rain
#

Well, if you wanted to do this with the structure and setup you have now, you could add a new exported variable to the Spawner script to reference your Marker2D node which you can later use when positioning the bullets:

@export var marker : Marker2D

..
bullet.global_position = marker.global_position
..

You would then just have to set the Marker value in the editor to the Marker2D node you have. This should be visible in the properties of your Spawner object, next to the Bullet Scene settings

This is a little brittle, as you would have to make sure to update this node if you were to switch weapons for example, but should work without many changes to your current set-up

dapper shoal
#

Would a better setup be to creat a gun scene. And have a 2D marker attached the the gun and then create the spawning script in that same gun scene and attach the spawn to the marker. And then that way I am able to just move the gun scene (with the marker and spawner attached) over to the player scene?