0 votes

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)

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 :)

in Engine by (184 points)

1 Answer

0 votes

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:


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)

by (1,756 points)
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.