Trying to shoot projectiles that don't follow the parent's coordinates

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

Hello guys, i’ve a problem and i’ve read every question related to this problem (cause i’ve seen a lot of this)

I’m trying to shoot bullets out of two cannons but i dont want them to follow the ship’s position cause that’s silly

Down here is my shoot function, setting the bullets parent to anything other than the ship doesn’t seem to draw them on the screen. they update and have the expected coords, but don’t work otherwise

I’m banging my head against the wall in this one, tried every solution i’ve seen to no avail, short of making the top-est node spawn the bullets instead of the player node.

Any insight would be appreciated!

func shoot():
if fr == 0:
	var bul1 = bullet.instance()
	var bul2 = bullet.instance()
	bul1.position = $cannon1.position
	bul2.position = $cannon2.position
	# i have also tried this
	print(str(bul2.position) +" " +str($cannon2.position))
	print(str(bul1.position) +" " +str($cannon1.position))
	fr = fire_rate
:bust_in_silhouette: Reply From: kidscancode

Since$cannon1 and $cannon2 are children of the player, their position is relative, so when you set the bullet’s position using the cannon’s relative position, in the parent’s space, nothing is going to be where you expect it.

In other words, the cannon’s position never changes as the player moves around - it’s always in the same relative position.

Instead use bul1.global_position = $cannon1.global_position

Aside from that, you’d have to share your bullet scene’s code to see if there’s anything else wrong.

thanks! changing to global position did the trick!

Also thanks for explaining why would that work and why mine wasn’t working.

It wasn’t the bullet script, it’s just position.y-= speed * delta in the process function for now

DefyingRelativity | 2019-06-17 18:10