Turret and Ship Body Doesn't Go Together

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

Hi, Striker here again, new project that i started today, a type of asteroids but the ships have a turret separate from the rest, a did a couple of trys atempting to make something that works, but when i’m getting close to conclude the prototype, the turret and the ship body collide in some way that my bullet come very far from the muzzle of the turret, when i put the turret and the ship separated everything works fine, the bullet is fired from the muzzle of the turret and the ship moves in the asteroids style, but when i combine the two parts is when everything begins to don’t go the way was planned… If someone could help me i would apreciate it, and sorry but my english isn’t the best.

What kind of spawn code are you using for the bullet?
If you are using some kind of offset math, then you will need to consider the parent also.

Mostly I like to use a node, to keep track of where the bullet should spawn, since a empty node isn’t much bigger than a vector.

MysteryGM | 2018-09-02 16:43

for the bullet i used a code from the godot docs, i searched up bullet and got to the kinematicbody2d page where had an example of a shotter that the bullet collide with wall and bounce off, they were explaining about move_and_slide and move_and_collide. My ship body uses the asteroids style movement and the turret follow my mouse pointer…

StrikerSVX | 2018-09-02 19:44

:bust_in_silhouette: Reply From: kozaluss

You probably should set the collision masks. Set the ship and turret on on collision layer, and bullet on the other one. Then set the mask inversely, so that bullet does not collide with the ship or turret.

Look here: https://forum.godotengine.org/4010/whats-difference-between-collision-layers-collision-masks

so i need to do this?

layer: player(1)=turret(1) != bullet(2)
mask: player(2)=turret(2) != bullet(1)

i dunno that, but from what i read i think is that way, right?

StrikerSVX | 2018-09-02 19:49

i read it on the godot docs a little more about masks and layers and i think i did solve something, but not what i was trying to solve, let me put this way, my ship start at the top left corner of the screen, my turret is pointing to my mouse cursor and my bullets go to the same direction, if i move the ship from left to right my turret start to aim way of my cursor and my bullet go in another direction, it like the muzzle its not connected and a ghost of my cursor is going to another position. but i checked more than three times and everything is fine from my perspective and all of this only happen when i put the turret to be the child of the ship.

StrikerSVX | 2018-09-02 20:25

This might be due to the local/global coordinates. Try to code aiming with globals: global_position, global_rotation and so on. This way you will get independent of the parent/child relation of the ship and turret.

kozaluss | 2018-09-02 21:07

i’m going to send my project to you so you can see, i really don’t know how to do some things yet.

Project link: (There is two scenes one called Space and the other called Space(Parent) the first has each node separate and the second is where the thing goes wrong, movement with the arrows and shoot with the left mouse button.)


StrikerSVX | 2018-09-02 22:49

Sure, no problem. Though it is night here in Poland now. I will look into this tomorrow

kozaluss | 2018-09-02 22:55

anytime you want, is night here in brazil too…

StrikerSVX | 2018-09-02 23:02

There you go:


I’ve repaired what I thought was not okay.
Also there are notes in GD files - please read.

kozaluss | 2018-09-03 13:25

Thanks for the help!

StrikerSVX | 2018-09-03 16:53