Translate a pixel using SetPixel on a Texture2D?

Hey guys, I been scratching my head about something with editing 2D textures in Unity and am finding it hard to describe my problem really, but bear with me - is there a simple way to do a simple transform of pixel(s) through SetPixel/SetPixels32 methods then applying to a texture - so that you do not leave behind the “old” pixels that have since moved to a new location in the texture? (these “pixels” are dynamic, they are affected by gravity and explosions which send them bouncing around the 2D scene)

A visual aid to help describe what I need to figure out:

  1. first we have a pixel in some location on a texture2D:

alt text

  1. then we transition the pixel (in this case only a single one - other times multiple) to another position:

alt text

  1. and finally we get rid of the old pixels position (here is the part I have trouble with):

alt text

So yeah I feel like its a pretty simple thing I am going for, but it escapes me how to properly get rid of the old position, especially when in a few frames, the pixels can shift dramatically (skipping several pixel lengths at high speed, before a collision detects) and I need an efficient way to determine where to “erase” the old pixel from… has anybody tried doing something like using SetPixel(x, y) and had to go back to erase the old pixel before Apply()'ing the changes to the texture? Also the position of the “pixel” is stored in an x, and y value format in an array of pixels that are in motion, so I can always check where a pixel is currently - how can I keep track accurately the last position the pixel was in, to “clean up” the positions that would be a dotted trail of where that pixel has traveled? How do you go about tracking individual pixels, and remembering where they came from/if they have moved at all since last frame (maybe they floated at the peak of a movement between frames and didnt actually move enough to go down a full pixel) and successfully cleaning up the old positions of the pixel?

Other possibly useful info:

-I keep track of where a pixel is supposed to be, based on a pile of clunky physics decisions to keep velocity looking realistic and bounce off the normal of local pixels after a collision…

-The texture which contains these dynamic pixels ALSO has a 2D pixel terrain, which has been through having all purple “sky” pixels iterated through and deleted from the texture (replaced by alpha 0 pixels) so thats what collisions are hitting.

-In doing this I must be sure not to erase “new” pixels that have just been drawn to their new position (which could be an “old” position of another pixel)

-I am not really asking you to write me some code, more like just your theory with an idea in pseudocode, but a simple example would be appreciated!

-One idea I had was to erase, then redraw every pixel that is dynamic (leaving terrain unchanged) but I felt like the overhead would be higher - maybe I am wrong about that? Wouldn’t I just create a new problem of combining separate images (the terrain texture, then the dynamic pixels texture after erase/movement calculation) into one image. Plus that creates a problem with dynamic pixels colliding with other dynamic pixels, which I don’t want…

-This is what a level looks like (before iterating through purple pixels and erasing them)

alt text

AND EVEN MORE info to show the problem (player is represented by red X of pixels) :

alt text

See that dang leftover pixel problem? How will I make that go away???

Store a copy of your original texture, then write that to your other Texture2D along with the pixel.