#Sine wave bullets are destroying my game's performance

23 messages · Page 1 of 1 (latest)

jade tundra
#

You could pre-calculate many values of sin and add them to a list. This is a very common way to increase performance with trig functions.

knotty dragon
#

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

frail relic
#

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?

knotty dragon
#

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?

frail relic
#

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?

knotty dragon
knotty dragon
frail relic
#

The game.

#

But yeah, would be good to see some code, too.

knotty dragon
#

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

frail relic
#

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()!

knotty dragon
frail relic
#

It's effectively just a variable if you use it like that. You could make your own variable (and not use CharacterBody2D).

knotty dragon
#

Oh wow there's 0 lag now

#

Making a separate Area2D sine bullet worked like a charm tysm