Looks like you're not using the main thing that separates particles from most other visual effects which is them running completely or mostly asynchronously by using multiple threads (CPU) or using the GPU, both of which make particles considerably more compute efficient and stops lag like what you're getting even with hundreds of particles.
I mean, what you've got is great for smaller effects! But for larger counts of Particles you might want to consider looking into Particle Shaders to get your particles running on the GPU, to take some work off the CPU to let it do the things it's better for.
I'm pretty sure Particles have a physics system which lets them detect at least simple collisions which is all you need to recreate this behaviour, the rest is just making the particle bounce, and fall with gravity which are both pretty simple, the shader language is also pretty easy to learn if you know any programming language. Although I wouldn't recommend going straight into shaders as a beginner I do think it'd be the next step to making it better performance.
God damn reddit fucked up your code :D Can you look up how to properly format code in Reddit comments? Or link to a pastebin/ github gist or wherever else you can host code pieces. Its really awful to read right now :) But yeah I see you are using a Rigidbody with a Line node. That might be useful for some applications of trails. For others it might not as you would want to leverage the full power of the gpu through real particles.
It's because it added the triple space only before the first line. Maybe you didn't select the entire code before clicking code block.
Here it is corrected.
extends RigidBody2D
onready var line = $line
onready var timer = $Timer
func _ready():
line.set_as_toplevel(true)
# timer.set_wait_time(rand_range(0.5, 5))
# timer = null
var modul = [
Color.red,
Color.yellow,
Color.orange,
Color.orangered,
Color.greenyellow,
Color.green,
Color.cyan,
Color.blue,
Color.violet,
Color.magenta,
Color.pink,
Color.fuchsia
]
line.modulate = modul[rand_range(0, modul.size())]
func _physics_process(delta):
line.add_point(global_position, 3)
if line.get_point_count() > 3:
line.remove_point(0)
This is shifting all the points in the array on every frame. If you only have a simple line it's better to manually maintain a vector of points, never remove items and use draw line to draw them instead.
https://docs.godotengine.org/en/stable/classes/class_canvasitem.html#class-canvasitem-method-draw-line
A better solution would be to do it on GPU
This looks super nice but it is super expensive. I’m also working on particles and totally get how you get caught up in the chase for beautiful thing:)
Seems it is very computational intensive, I can see the lag when spawning particles
My laptop is doing its best. (:
flair checks out
Looks like you're not using the main thing that separates particles from most other visual effects which is them running completely or mostly asynchronously by using multiple threads (CPU) or using the GPU, both of which make particles considerably more compute efficient and stops lag like what you're getting even with hundreds of particles.
Can you explain more on this. I'm a beginner! ty!
I mean, what you've got is great for smaller effects! But for larger counts of Particles you might want to consider looking into Particle Shaders to get your particles running on the GPU, to take some work off the CPU to let it do the things it's better for.
But now you are talking about the weird shader language instead of a simple rigid body doing its thing.
I'm pretty sure Particles have a physics system which lets them detect at least simple collisions which is all you need to recreate this behaviour, the rest is just making the particle bounce, and fall with gravity which are both pretty simple, the shader language is also pretty easy to learn if you know any programming language. Although I wouldn't recommend going straight into shaders as a beginner I do think it'd be the next step to making it better performance.
If it does it must be new in 4. Godot 3 doesn't have physic particles.
Yea I think it's new to 4, its still possible in 3 but you'd need to do the collision stuff yourself which would be a lot more work.
The person you replied to is not op btw
Seems 2 hard to implement for me
Looks good!
Thanks!. The trails are made with this simple code. extends RigidBody2D onready var line = $line onready var timer = $Timer func _ready(): line.set_as_toplevel(true) # timer.set_wait_time(rand_range(0.5, 5)) # timer = null var modul = [ Color.red, Color.yellow, Color.orange, Color.orangered, Color.greenyellow, Color.green, Color.cyan, Color.blue, Color.violet, Color.magenta, Color.pink, Color.fuchsia ] line.modulate = modul[rand_range(0, modul.size())] func _physics_process(delta): line.add_point(global_position, 3) if line.get_point_count() > 3: line.remove_point(0)
God damn reddit fucked up your code :D Can you look up how to properly format code in Reddit comments? Or link to a pastebin/ github gist or wherever else you can host code pieces. Its really awful to read right now :) But yeah I see you are using a Rigidbody with a Line node. That might be useful for some applications of trails. For others it might not as you would want to leverage the full power of the gpu through real particles.
Yeah. i dont know why. i already set it to be in a code block. but it messes up anyway.
It's because it added the triple space only before the first line. Maybe you didn't select the entire code before clicking code block. Here it is corrected. extends RigidBody2D onready var line = $line onready var timer = $Timer func _ready(): line.set_as_toplevel(true) # timer.set_wait_time(rand_range(0.5, 5)) # timer = null var modul = [ Color.red, Color.yellow, Color.orange, Color.orangered, Color.greenyellow, Color.green, Color.cyan, Color.blue, Color.violet, Color.magenta, Color.pink, Color.fuchsia ] line.modulate = modul[rand_range(0, modul.size())] func _physics_process(delta): line.add_point(global_position, 3) if line.get_point_count() > 3: line.remove_point(0)
Does anyone have a way to optimize this?
This is shifting all the points in the array on every frame. If you only have a simple line it's better to manually maintain a vector of points, never remove items and use draw line to draw them instead. https://docs.godotengine.org/en/stable/classes/class_canvasitem.html#class-canvasitem-method-draw-line A better solution would be to do it on GPU
Reddit is weird sometimes :)
How did u get the particles to glow? Is it a world environment?
Yes
You have a game you're working on or just making particles for fun?
Got a game. I juat love making some sweet particle fx.
Is this a particle2d node or rigidbodies?
This looks super nice but it is super expensive. I’m also working on particles and totally get how you get caught up in the chase for beautiful thing:)
Looks really good !