I have a GPUParticles2D that emits 4 particles with explosiveness. I want to make these particles spread evenly, so it would be something like 45°, 135°, 180° and 225°. If I could make them spread like 30°, 150°, 210° and 330°, it's even better.

  • xyz replied to this.

    UpsetChicken Convert particle process mateial to shader and make an intervention in the shader code that snaps the angle to those specific values.

      xyz

      xyz I don't know much about Shader codes. Could you give me an example of how to do this?

      • xyz replied to this.

        Hey, I managed to make a shader code to do this, but my particles don't move anymore. Can you help me?

        shader_type canvas_item;

        uniform vec2 direction1 = vec2(4.0, 1.0);
        uniform vec2 direction2 = vec2(-4.0, 1.0);
        uniform vec2 direction3 = vec2(4.0, -1.0);
        uniform vec2 direction4 = vec2(-4.0, -1.0);
        uniform float time_scale = 1.0;
        uniform float speed_factor = 100.0; // Speed factor for particle movement

        void fragment() {
        // Use a random value to choose a direction
        float random_value = fract(sin(TIME * time_scale) * 43758.5453);
        vec2 selected_direction;

        if (random_value < 0.25) {
            selected_direction = direction1;
        } else if (random_value < 0.5) {
            selected_direction = direction2;
        } else if (random_value < 0.75) {
            selected_direction = direction3;
        } else {
            selected_direction = direction4;
        }
        
        // Calculate movement based on time and selected direction
        vec2 position_offset = selected_direction * speed_factor * TIME;
        
        // Offset the fragment coordinates to create movement
        vec2 uv = FRAGCOORD.xy + position_offset;
        
        // Set the color based on the new fragment coordinates
        COLOR = vec4(1.0, 1.0, 1.0, 1.0); // White particles

        }

        • xyz replied to this.

          UpsetChicken You need to use a particle shader assigned to particle_material property of the particle system node, not a canvas item shader.

          Much easier to do it from script with emit_particle() though.