How to give a cannon to a character?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Undead_Rufus
:warning: Old Version Published before Godot 3 was released.

Hello everyone,
i will start with my problem that is strange. I started with Godot engine a couple of weeks ago and i was trying to create something after watching tutorial videos.

Well, my problem is, when i try to combine a cannon and a squared character from tutorials to create something like a character with weapon, it works very strange.
I tried to add a cannon to rotate so it could fire in different directionsscene
but now cannon balls spawn under the platform.square and cannon

Separate they work, but together not and i don’t know why.

(Sorry for bad english)

I’m working on this rn, if I get it working to a polished level I’ll publish as a plugin.

jarlowrey | 2017-05-04 16:46

:bust_in_silhouette: Reply From: eons

Instance the balls on the level, not as children of the gun/player (maybe you are already doing this).
Then use global position (get/set_global_pos) to place them on absolute coordinates.

Sometimes you may want to use global rotation too.

Sorry, i don´t understand what you mean

Undead_Rufus | 2017-05-04 15:54

Something like:

var cannonball = Cannonball_scene.instance()
cannonball.set_global_pos(cannon.get_global_pos())
node_where_cannonballs_are_placed.add_child(cannonball)

eons | 2017-05-04 17:47

:bust_in_silhouette: Reply From: rredesigns

Your bullets are spawning in the place where the gun was positioned originally. Before instancing them set their position in global coordinates.

Also check what the other user said, add the child bullets to the root node, not to the player. The easiest way to do that is get_tree().get_root().add_child(bullet)