Help with Particle effect: "pixel" explosion.

Hi guys, first of all I realize this might not be the place for this topic but I couldn’t find any subforum with particle discussions, so sorry and if there is an appropriate place do tell me :).

So, I’m currently working in a 2D Arkanoid/Breakout/Brick Breaker game style.
It’s just a “learning” project, I will publish it with ads and all but I don’t expect much to come from this.
Nonetheless I want to make it as fun as I can, and a lot of this comes from the visual experience of the game.

Ok, sorry for the intro.

When I destroy a brick I’d like it to break into little squares that fall to the void (?)
2652884--186942--somethinglikethis.png<<< something like this, with even squares and not as ugly :p. Using the example to let you know the approx. size I want the little squares to be.

Searching through forums and tutorials it seems that a Particle System would be the best, and in this topic I found one that works similar to what I need:

https://dl.dropboxusercontent.com/u/7761356/UnityAnswers/Web/SpriteExplosion/build.html

So, I implemented it in my game and it “kind of” works the way I need.

I’ll paste the code below:

using UnityEngine;
using System.Collections;

public class SpriteExplode : MonoBehaviour
{
private SpriteRenderer spriteRenderer;
private Transform spriteTransform;
public float ppu = 1.0f;
Vector3 GetWorldPos(float aX, float aY, Bounds aBounds)
{
aX -= 0.5f;
aY -= 0.5f;
return spriteTransform.TransformPoint(new Vector3(aBounds.center.x + aX * aBounds.size.x+0.5f/ppu, aBounds.center.y + aY * aBounds.size.y+0.5f/ppu));
}
public void Explode(SpriteRenderer aSpriteRenderer)
{
spriteRenderer = aSpriteRenderer;
StartCoroutine (Explode());
}

IEnumerator Explode()
{
spriteTransform = spriteRenderer.transform;
var pixelScale = Mathf.Sqrt(spriteTransform.lossyScale.xspriteTransform.lossyScale.y);
var sprite = spriteRenderer.sprite;
var partSys = GetComponent();
// TODO:
// In Unity beta there is pixelsPerUnit so you don’t need to specify it manually
// ppu = sprite.pixelsPerUnit;
int x = (int)sprite.rect.x;
int y = (int)sprite.rect.y;
int w = (int)sprite.rect.width;
int h = (int)sprite.rect.height - 10; __
<== I do this so the white “shine” of the brick isn’t included__
Bounds bounds = sprite.bounds;
var particles = new ParticleSystem.Particle[w * h];
Debug.Log("Rect; " + sprite.rect + " : " + sprite.bounds);
Debug.Log("W/H " + w + " / " + h + " x/y " + x + " / " + y);
var colors = sprite.texture.GetPixels(x,y,w,h);
Debug.Log("Color Count : " + colors.Length);
var p = new ParticleSystem.Particle();
p.size = pixelScale/ppu;
//p.axisOfRotation = -Vector3.forward;
for(int yi = 0; yi < h; yi++)
{
for(int xi = 0; xi < w; xi++)
{
int i = xi + yi
w;
if (colors*.a <= 0f)*
p.startLifetime = p.lifetime = -1;
else
{
p.position = GetWorldPos((float)xi / w, (float)yi / h, bounds);
p.color = colors;
p.startLifetime = p.lifetime = 1.0f;//Random.Range(-1.0f, 1.0f); for some reason the random
var velocity = Random.onUnitSphere * 1 + Vector3.up * 1; doesn’t work here.
velocity.y = Random.Range(-0.1F, -1.0F);
velocity.z = 0; // only move in x-y plane
velocity.x = 0;
p.velocity = velocity;
p.rotation = -spriteTransform.eulerAngles.z;
p.angularVelocity = Random.Range (-1f,1f);
}
particles = p;
}
}
partSys.SetParticles(particles, particles.Length);

Debug.Log("Count: " + partSys.particleCount);
spriteRenderer.enabled = false;
yield return new WaitForSeconds(1);
}
}

Ok, so in my game bricks are imported at 90 Pixels Per World Unit. If I use this number in the variable ppu, the result is something like this: 2652884--186945--brickpowder.png

The size of all the particles is right or at least close, but each individual particle is very small so instead of a square it looks like a little dot creating a powder-like effect. It’s “nice” but not correct.

Then, I change the ppu value to 9 and it looks like this: 2652884--186946--brickdsfjagj.png

The individual particle size is better, but there are a lot of particles in a very small space so it looks ugly.

So, I need the second particle size with the first “allparticle” size. I assume I need to show less particles but I don’t really know how to do that.

Can anyone help me?

Sorry for the long post, and the poor english level :smile: I hope you were able to understand me.

Thanks for your attention and help!

Maybe you can create one mesh with 1 quad for each of the pixels in the texture and animate them on the GPU using a geometry shader - like a particle effect spreading apart ?