Hi!
I want to make a game like this: https://play.google.com/store/apps/details?id=smellymoo.sand&hl=en&gl=US
The problem is that I don’t know how to make the particles or the physics, does anyone know it?
Thanks.
Interesting game… I’m not sure you’d have much success using Unity’s particle system this way, or even the physics.
The particles in Unity are mostly intended for presentation, so once fired there is little facility to process them after they are underway (eg, to collect them or stack them)
The physics in Unity are mostly geared towards a number of moving objects in the low few hundreds range. Any more and it will slow down massively. The screenshots of that game seem to show hundreds of thousands of actively processed particles.
There might be something you could do with the new DOTS/ECS stuff but I haven’t messed with that personally.
You could write it in native code and it would probably be fast enough, then integrate the native code with Unity and use Unity just to present the results. I do that with my SNOW2005 demo thingy but it’s just some junk fool-around code I made one day. It’s in straight C and part of a larger hacky module (eg, it won’t compile the way it is), but it’s just simple cellular automata, snow then rain, back and forth.
Here’s a video of the above code in action:
I have used particles to create a “starfield”.
int numstars = 500;
Particle[] starparticles = GetComponent<ParticleEmitter>().particles;
for(int i = 0; i < numstars; i++)
{
starparticles[i].position = new Vector3(Random.value*10f,Random.value*10f,Random.value* 10f);
starparticles[i].color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
}
GetComponent<ParticleEmitter>().particles = starparticles; // reassign the changed data
To change the colors:
ParticleAnimator particleAni;
particleAni = ((ParticleAnimator)(tmpobj.GetComponentInChildren<ParticleAnimator>()));
Color[] aniColors = particleAni.colorAnimation;
for (int j = 0; j < aniColors.Length;j++)
{
aniColors[j] = Universe.Stars[i].starcolor;
}
particleAni.colorAnimation = aniColors; // das temoräre array auch wieder zuweisen um nicht auf der kopie zu arbeiten die dann verworfen wird
Note that this is for the old/ancient/legacy particle system. Not for Shuriken. But you could look if there are similar possibilities.
And AFAIK particles could also have a world particle collider but I have never messed with this. Maybe that helps to physically simulate them?
The world of particles in Unity is a bit confusing to say at least. There is legacy particles, Shuriken and now Visual FX graph. And there are dozens of custom particle solutions in the store (for GPU too, fe this one ). So If I were OP I would have a look around becauses chances are that there is something close to what you want to achieve.
There are some examples here of how to use c# jobs and burst with the particle system. It allows you to manipulate thousands of particles efficiently from script: Particle System C# Job System support
maybe it could help as a starting point if you chose to use that system.
the app you linked looks like a 2d fluid simulation. You could definitely achieve something like that with the tech I linked above. Plus some Googling to learn about fluid sims eg SPH, Position Based Dynamics, are some good search terms. There are already examples of fluid tech written with Unity on GitHub etc.