#Sine wave bullets are destroying my game's performance
23 messages · Page 1 of 1 (latest)
That sounds like a good idea, but I would need to store A LOT in this case since I have variable speed and frequency parameters where
y = amplitude * sin(frequency * delta * speed)
So I could either calculate them and store them based on speed and frequency when the game/scene starts or just make a huge dictionary, but both options sound difficult and memory consuming
It's more likely that the quantity of bullets is the problem and not the maths you're using.
Is the performance any different when you remove the sin() call?
Yeah it runs pretty smoothly as long as there are no waves on the screen but it might be attributed to the count as you suggested
What would be a good workaround? To show the same "fluidity" of the sine wave without a high number of bullets?
You can just change that line to y = amplitude and skip the sin() bit to see if it's any faster that way. if it isn't, there's no point in trying to improve the calculations. You'd need to fix how you're drawing/moving/colliding the bullets instead.
Can you show a picture of it?
What kind of node is used for the bullets?
Setting it to just amplitude did remove all the lag, but I don't get it since I am already using 4 other trig functions in the rotation function
The code?
node is characterbody2d btw because I use multiple patterns for the same bullet and one of them requires velocity. I am guessing I have to make a new node for each pattern
That's the problem. CharacterBody2D is very expensive when you have a lot of them.
Use Area2D instead and add a simple script to handle movement.
Also make sure the collision layer settings don't allow bullets to detect other bullets.
Actually, even just doing that might fix the problem.
Hmm, you're not even using velocity there because you're using move_and_collide() instead of move_and_slide()!
Yeah that should make some difference especially because I am simply setting position not velocity
It's effectively just a variable if you use it like that. You could make your own variable (and not use CharacterBody2D).