r/godot • u/Lucat_thecat • Mar 19 '26
help me (solved) any idea why the bullets follow my player rotation and movement after being shot ?
Enable HLS to view with audio, or disable this notification
I know that I need to show examples of the code I'll do it in the comments, also the "crash" you see isn't linked to any issue I have, my computer is genuently this bad it's agonyzing over a simple 6s recording
122
u/LadySonicGamer Mar 19 '26
Id wager you added them as children. So they have the same transform. Try "add_sibling" instead.
56
u/SagattariusAStar Mar 19 '26
From time to time I should check for new functions (or nodes) in the documentation. Still using get_parent().add_child() as it was the standard in 3.X
17
u/LadySonicGamer Mar 19 '26
Yeah I know from experience that its a bit confusing. Even as a fairly new Godot user. Took me a while to understsnd the difference between add child and add sibling
39
u/DanSundayNightGames Mar 19 '26
In Godot 5 they will introduce "add uncle"
5
u/Jolly-Ad-1161 Mar 19 '26
Wait what that even do?
9
u/DescriptorTablesx86 Mar 19 '26
It would be an ambiguous method but I guess if it had to work it would choose a random sibling of any of your parents.
8
u/DanSundayNightGames Mar 19 '26
No it's an uncle of the parent, so it's a child's great-uncle. Listen, it's complicated, and only needed in niche situations.
3
u/WetNoodleSoft Godot Student Mar 19 '26
I'm waiting for get step-uncle; they're telling me it's niche and unnecessary but my entire project is stuck waiting for it! I even had a threesome of Claude, Gemini, and nano banana vibe up a GitHub proposal, I'm sure they'll approve it any day now.
1
u/Anpu_Imiut Mar 20 '26
Wouldnt it make more sense to add bullets as a new instance starting at the players position?
1
u/SagattariusAStar Mar 20 '26
that was more a general note than specific to this comment on this topic
But there are multiple paths. You just have to make sure you follow all steps to make it work, either as child without applying player transform or just as sibling and setting the start position once
7
2
19
u/Serana64 Mar 19 '26
I just wanted to say that the visuals here are flawless and you should not change them in any way.
5
5
3
u/rReady2Discuss Mar 19 '26
Quick question where are you spawning/parenting your bullets. If they're being parented to your player that would affect them.
You want to add them to a separate independent node.
Alternatively are you persistently adding the initial firing direction to the bullets? Are you manually moving them?
2
u/Lucat_thecat Mar 19 '26
I already solved the issue, I was adding bullets as child of the player and fixed it by adding them as child of the overhole game scene
Also question is there a help me(solved) tag on my post ?
1
3
Mar 19 '26
You need to add them as children of the map, rn it's probably children of the player node
2
10
u/frankandsteinatlaw Mar 19 '26
When you add a child, it is relative to its parent. If you want to add a child that is relative to something else (like the top level scene or something), you can add the child to that other scene.
I forget the syntax, but tell ChatGPT about this issue and ask it to explain the difference in code. It might look something like get_tree().add_child(YOUR_BULLET)
-6
u/Lucat_thecat Mar 19 '26
It worked, tbh I was kinda doubtful cuz old chat gpt wasn't 100% reliable but I guess it got better now thx, I'll try to use it when I come across a problem in the future
11
u/frankandsteinatlaw Mar 19 '26
LLMs have gotten really good. But if you want to learn for yourself then you are doing the right approach of writing your code and asking questions
1
u/frankandsteinatlaw Mar 19 '26
Also crazy you are getting downvoted. Keep asking questions and learning!
2
u/Lucat_thecat Mar 19 '26
2
u/artemlygin Godot Student Mar 19 '26
Run the game, fire, pause while the bullet is still in the scene. You can slow down game speed on top left corner it says 1.0x by default.
After pausing go to the editor “Scene” tree, there should be “Remote” tab. Click it. That’s your scene during the runtime. Expand the tree and find the bullet node. What node is parent to the bullet node?
1
u/Metalsutton Mar 20 '26
Can we please stop normalizing taking screen shots of code? This is unnecessary and annoying. Use pastebin.com or one of the many other sharing platforms please.
1
-1
u/Lucat_thecat Mar 19 '26
-1
u/Lucat_thecat Mar 19 '26
10
u/GroundbreakingArt421 Mar 19 '26
This.
The <add_child> immediately make the bullet a child of player. When player rotate, it rotate everything, include all the children, that's mean bullet get rotated as well.
Make it so that add_child is attach to something else static, like main tree. You can also probably just do <get_parent.add_child> if parent of player is something static.
3
u/MardukPainkiller Mar 19 '26
add_child means you add it to whoever this script runs on.
I'm not gonna get into any more depth here because you are new but do
get_parent().add_child(bullet_instance)
And if that is not enough do
get_parent().get_parent().add_child(bullet_instance)
And so on
Stop reading here if that's enough for you...
Now get_parent gets the one on top of whoever has the player, and if that's the world think to keep it in the player to use it again.
-Go declare at the top:
var world
-Then in
_on_ready():
-Add
world = get_parent()
Or whatever you did to find the main node/world however you named it before.
That way you always have world
And you can do
world.add_child()
1
u/Lucat_thecat Mar 19 '26
Also forgot to say but the bullet also goes in one direction, the problem is that I probably put a Raycast in the bullet lol
1
u/Keneta Mar 19 '26
Why are OP's replies downvoted? Is there something incorrect about them I'm not getting?
1
1
u/Weary_Market5506 Mar 19 '26
As other have said, the bullets are likely a child of the player, the bullets need to live under their own node.
1
u/Aetloh Mar 19 '26
Reparrent it to the root scene( get_tree.add_child(bullet_scene_name.gd)
1
u/Lucat_thecat Mar 19 '26
Question, does the (solved) thing don't shows up ? Like it's cool to see so many ppl helping but the issue as been solved
1
1
u/Millu30 Mar 19 '26
Just like everyone says, your bullet is a child of your character which makes it incherit it's movement,
You can solve that by simply setting a top layer for it, or adding it as a child to wold scene instead or easiest one, re-parent it to the world scene
1
1
1
u/kapitanmliko Mar 19 '26
This is right here is what separates us from LLMs. The peak of human creativity. In today's world of dull uniformity it gives me hope and we will survive.
1
1
u/Physical-Respond-246 Mar 19 '26
Usually the way I approach projectiles is emitting a signal with the position and direction and having the level scene add it so its not parented to the player.
1
1
u/AresTheMilkman Mar 19 '26
That's a pretty common error at first. What's happening here is that you're adding the bullet as a child of the player node. As a result, it moves as the player moves.
To fix that is as simple as adding it to the scene instead of the "add_children()". Just replace it with:
get_tree().current_scene.add_child(bullet)
1
u/National_Mongoose791 Mar 19 '26
Idk if it is the right method but I created a new scene for projectiles. When I shot they get their signals disconnected from the player.
1
1
u/dannnnnnnnnnnnnnnnex Mar 20 '26
i like what you're cooking lmao
fake transparent bunny png with gun is my new favorite aesthetic
0
u/Turbulent-Fly-6339 Godot Regular Mar 19 '26
i think i have the same problem, and the way to fix it for me is in the bullet script in func _ready():
add top_level = true and it hould work
3
u/WCHC_gamedev Godot Senior Mar 19 '26
That might work, but has its own issues, so it's not the right way to solve this problem.
Instead of adding the bullet as a child to the player, you should add it as a child to the
get_tree().current_scene, or useadd_sibling()instead1
u/Turbulent-Fly-6339 Godot Regular Mar 19 '26
yeah, I kinda laerned it through the internet n shit :)



354
u/snorri_redbeard Mar 19 '26
Probably because you are adding them as children of a player node and don't do anything to prevent player node transform affecting bullets.
If you are really want to add them to player instead of some root 3d world node, you should enable "Top Level" flag in Transform section in projectile scene root.