- Home /
2D pixel collision & destruction
Hi all
I'm building a 2D top-down farming game, and I'm building the system to harvest crops.
My first thought was to have the combine harvester drive over the "pixels" and harvest them, kind of like using the eraser in paint, but I can't find any solid leads on how to achieve this.
Most searches ended in people trying to make worms clones, which seems overboard for my needs, but it also revealed this this sort of pixel-lvel collision detection is a huge obstacle for Unity to overcome.
I mean, I could use separate colliders for each pixel, but that's very heavyweight for what is, at the end of the day, a simple part of the game.
I've implemented a system of larger "pixels" with their own collision detection, but it's not as pretty or as elegant as my original idea, and an entire block disappearing as soon as it's touched isn't nice.
Can anyone offer a nudge in the right direction?
Answer by FortisVenaliter · Aug 21, 2015 at 04:17 PM
The best way to do this would be with a texture mask. You want an invisible texture that represents your field. Black is harvested, and white is harvestable. Then, when you drive over it, you color any white pixels covered by the harvester black.
In the shader for drawing the farms, you need three textures at least: Unharvested diffuse, Harvested diffuse, and the mask. You'll then sample the mask, and use that to lerp between the two diffuse values.
That sounds perfect! How would collision detection work on a setup like this? I mean, finding a pixel-perfect point on the texture to change the mask?
Your answer
Follow this Question
Related Questions
Why Does Object Keep Getting Faster? 1 Answer
How do I make my player jump? Unity 2019,How do I make my player jump? 1 Answer
OnCollisionEnter2D not triggered 3 Answers
Lag Caused by Overlapping 2D Colliders 1 Answer
Model stuck on collider 1 Answer