0 votes

Hello, I am trying to make a bullet hell game, and I am calculating the sin(x) of each bullet in every frame to move it. This is causing lag when the number of bullets goes up. I was wondering if anyone has any other strategies for making bullet hell patterns, or if anyone knows how to use the trig functions with less lag. I can put together an example if it is needed, but thanks in advance fr your help!

Godot version Godot4.0.rc2
in Engine by (60 points)

This really depends on your game and where the bottleneck is (simple sprites usually wouldn't incur much overhead). Perhaps an alternative is to decouple the calculation from the movement code so it can run in parallel, with the movement code then just using the result.

You might also consider a plugin: https://github.com/samdze/godot-native-bullets-plugin

You may like the MultiMesh strategy: https://www.youtube.com/watch?v=-r4o3JWzw4U

@spaceyjase, the plugin you mention isn't compatible with Godot 4 at time of writing.

Do you think that there would be a noticeable difference using a multimesh over sprites? Right now I am just instancing sprites and using the PhyscisServer2D to move them.

2 Answers

0 votes

Also, are You sure it is the movement that causes lag spikes ? I would rather think, that the lag lies in instantiating and childing massive amounts of bullets. GDQuest made some good tutorials about precaching bullets for bullet hell game, that eliminates the lag entirely.

by (8,099 points)
0 votes

What Inces pointed out was my guess too. I bet it's the number of projectiles being instanced that is lagging the game. You should try removing any movement logic from the bullets, and try to shoot to see if it still lags. If the game lags when you shoot without moving the bullets, the number of instances are lagging the game. If it doesn't lag, then the sin function is lagging the game.

If the number of instances is the source of the lag, I suggest pre-instancing your bullets, so that they already exist (invisible with disabled collision boxes) when you shoot them, so you just have to make them visible and activate the collision detection instead of adding a new bullet to the scene tree each time

by (1,076 points)

Not just instancing, queue_free() can also cause this in quick succession.
A render / pool bucket is the best way to go like Inces said

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.