Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bullets spawn elsewhere when root node is moved #39

Open
blabtonic opened this issue Nov 3, 2023 · 13 comments
Open

Bullets spawn elsewhere when root node is moved #39

blabtonic opened this issue Nov 3, 2023 · 13 comments

Comments

@blabtonic
Copy link

Whenever I attach the BulletServer & BulletSpawner to a CharacterBody2D (or a node attached to a CharacterBody2D), then place the CharacterBody2D node on a different scene I noticed that the bullets do not spawn at the point given within the radius

Screenshot of the CharacterBody2D node the spawner is attached to the right of the object a few pixels away
Screenshot from 2023-11-02 21-02-24

Now attached to a different node with the CharacterBody2D as a child, moved the node into the middle of the screen. Radius is still shown right next to the CharacterBody2D node but the bullets appear in a different position
Screenshot from 2023-11-02 21-02-54

@quinnvoker
Copy link
Owner

Hey, thanks for the bug report! I see what you mean, and I think the issue is that the BulletServer node isn't designed to be attached to anything that can move. So in your case you could probably resolve this by removing the BulletServer from the Brutus scene and putting it in the Level scene instead.

I'll keep this issue open though, because small scenes instancing their own bullet server to use is a use-case that should be supported, and I'd like to make changes to allow for that when I have time. It should be just a matter of adding a toggle on BulletServer that ensures it's always positioned at a global (0,0) regardless of where its parent is.

@blabtonic
Copy link
Author

Thanks much appreciated 😄 BulletServer on the base level does make sense after that moving the node with the BulletSpawner to that level does work and I'm able to instantiate the scene as a child

@fryedrycestyle
Copy link

fryedrycestyle commented Dec 16, 2024

I apologize for necroposting a year+ later, but I've encountered a similar issue in Godot 4.4 even with a single bullet server in the scene. See the screenshot below for a little more info on the scene structure, but basically I have a parallax scrolling level that the player is moving through and the bullets don't work as a result. If I stop the parallax movement and just put the enemies on the screen visible to the player, they work fine.

On top of that, if I still remove the actual movement and instead just try to spawn enemies just off screen and move to the screen when a timer expires, the issue still persists. As long as the enemies or screen don't move, the bullet patterns work fine, but the moment anything moves (be it the enemies themselves or the parent parallax scroll), the bullet spawning breaks - a couple bullets appear but then quickly dissipate with no new bullets spawning they also don't appear to be spawning from the actual enemy either as seen below

image

Here's the scene layout. As a note, I've moved the bullet server into the parallax b/c the bullet patterns were even more broken when it was just a child of the main scene:

image

Here's the Bullet server setup:
image

Here's one of the "red enemy" bullet spawners:

image

Any idea what's causing this? How can I resolve it?

@quinnvoker
Copy link
Owner

quinnvoker commented Dec 16, 2024

Hi, the issue you're facing here is the same as the original post's, and has the same solution I already described above: Do not make the BulletServer node a child of any node that moves. Since all bullets are essentially children of the bulletserver, if the server moves, the calculated locations of bullets move with it, causing that weird behaviour and displacement.

If you move your existing server node out of the Enemies tree and instead make it a direct child of Main, there shouldn't be any problem.

I don't mind necro-ing an old thread if necessary, but next time please try the suggested solution from the thread first.

@quinnvoker
Copy link
Owner

Oh and good luck with your project by the way! It's looking pretty cool.

@fryedrycestyle
Copy link

From my post:

As a note, I've moved the bullet server into the parallax b/c the bullet patterns were even more broken when it was just a child of the main scene

Basically the issue persists regardless of that. I did read the suggestion, and yet I still see issues.

@quinnvoker
Copy link
Owner

Sorry for missing that note in the middle of your post, but all I can work from is your description of the problem and what you've shared with me, and all you've shared is a node configuration that's been stated to be unsupported by the module.

I don't have enough insight into your project to know anything else that might be going wrong with it, and just saying that it's "even more broken" when configured correctly doesn't give me enough context to debug.

@fryedrycestyle
Copy link

Apologies if I came off terse - I Just wanted to call out that I had in fact done it both ways and was encountering issues regardless.

When not in the parallax the bullets still exhibit the behavior, I initially described. Additionally, they fire in the reverse direction.
In a separate test scene with no parallax scrolling and just the player as a moving object, I'm seeing similar issues with the bullet spawner and servers and am seeing similar behavior but still see issues with bullet spawning. They just kind of "flicker" in front of the enemy.

See the below GIF:

2024-12-1616-07-14-ezgif com-video-to-gif-converter (1)

What info can I provide here to help troubleshoot further?

@quinnvoker
Copy link
Owner

That gif is extremely helpful context, thank you!! It appears to me that there might be an issue with the bounding box that bullets are confined to, since they appear to spawn and then pop immediately on the next frame...

As an experiment, does it behave the same way if you change the server's "Play Area Mode" to "Infinite"? If that fixes it, you might be able to get away with using an infinite play area and using the bullets' max lifetime to despawn them instead of automatically despawning them when they go offscreen, or maybe some manual play area setup could work for you.

@fryedrycestyle
Copy link

Interesting. The infinite trick didn't seem to do it, but the bounding boxes did appear to be part of the issue: I had to offset the spawner outside the collision box of the enemy ship, and then the bullet pattern worked as expected. The bullets, I assume, were popping while moving in the collider?

The next issue was making the enemy move. It seems that having the enemies as part of the parallax (a lazy way to get them to appear like they're flying by you during the level, I suppose) is the other big issue. Even if the server is detached, when the ships are parented to a parallax group, the behavior is now the flicking exhibited in the test scene.

The fix seems to be removing them from the parallax all together and having them move separately, which means I have to rework how enemies appear on the scene. However, while it may be a little more work on that front it does seem to function now, so I can work with this if it's how the system works.

I guess the only remaining question is: should it still work if the enemies are children of the parallax? Is this behavior still weird or is this actually in line with how the underlying code powering the system works?

@quinnvoker
Copy link
Owner

I think in theory it SHOULD still work if the enemies are part of a parallax group like that. Not sure offhand why it wouldn't, but to be honest I haven't built anything with that kind of setup so it's possible there's something I overlooked when writing the module.

I'm curious if your enemies are using the same collision layer as the bullets they're firing... because in that case when the bullets spawn within the ship's collision shape, they'll "collide" with it and pop like we're seeing above. If they are using the same layer, try changing the bullets to a different collision layer and see if the parallax problem still occurs. If they're on different layers, feel free to ignore this tangent lol.

@fryedrycestyle
Copy link

That also appeared to be part of the issue, yes (in both the test scene and the actual scene with the parallax scrolling). I moved the spawner down to compensate for that as I had other logic requiring the collision of bullets be on the same layer as ships that if not for the fact this is jam game, I'd probably just re-do.

@quinnvoker
Copy link
Owner

Great, glad we managed to get to the bottom of it, and that you seem to have things working now! Best of luck with the jam, and I'd love to see the game when you're done with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants