many projectiles moving : lag - 2d.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By quizzcode

Hey there,
I was wondering if someone know a way to optimize projectile motion ?
I have 2d sprites moving at their target in my physic delta.
Once arrived, they deal damage.

I have noticed that passed 50-60 projectiles, the game in debug mode lags quite a lot.

This is what I use for the moving of the projectiles :

global_position = global_position.move_toward(target.global_position, 8)
look_at(target.global_position)

Anyone knows a way to optimise it ?
I looked into mesh, but my projectiles are different from each others, up to 6 different at once.
I read that mesh is only good pass 500 unit

thank you for your input :slight_smile:

:bust_in_silhouette: Reply From: Thomas Karcher

Hm. Even if you used individual nodes for every single projectile, Godot should be able to handle way more than 60 of them (usually 500 to 800 on my office laptop). So I guess you should be able to optimize your project even without using a completely different approach by checking the monitors in debug mode (errors / warnings / number of objects etc.)

Alternatively, you could check out the test project I did a while ago, optimizing the calculation and rendering of thousands of ships orbiting a planet:

Results:

  1. Direct calls to the VisualServer are faster than rendering individual nodes.
  2. Custom particle shaders are way faster than anything else.

(But for these approaches, you’d have to implement your own projectile physics and collision detection)