Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Physical_Liquid_Conor

Pages: [1] 2 3 ... 14
Request Features / Re: Body linear velocity limitation
« on: December 08, 2015, 05:13:16 pm »
Are you trying to have a global maximum velocity for all bodies or a maximum velocity per body?

Also do you expect particles to observe this velocity limit? I don't think that there is an efficient way to achieve this other than setting the box2d constants internally.

Request Features / Re: Body linear velocity limitation
« on: December 08, 2015, 02:07:29 pm »
Box2D already has limits on how far a body can move per step(or sub-step) but it probably isn't exactly what you are looking for. The value for how far the object moves is derived from other values in the engine and is not set by the user.

I will consider adding a function to limit the velocity each frame. However this is not as simple as it might seem at first.

Take a look at this topic :

If the engine performs sub-steps then I will need to cap the velocities during each sub-step. Otherwise a body could have forces applied to it that move it by more than the capped velocity allows. Even then this does not guarantee that the velocity will never exceed the maximum as a force will have taken effect for one step before the velocity exceeds the maximum and can be capped.

I will test this out and as long as it does not effect performance or existing code I will add it.

General support for Liquid Physics 2D / Re: Water by tubes
« on: December 08, 2015, 01:48:35 pm »
Hi Warped,

Yeah it is possible to make water flow along a tube. Check out the example in the LiquidPhysics2D/Testbed folder called "Pump.unity". This shows how you can use a particle accelerator to move particles along the length of a tube.

If you would like it so that only water can move through the tube you can use a fixture at the entrence with collision filtering to prevent bodies from traveling down the tube.

Yes you can save a configured fixture to a prefab and instantiate it later. You will need to instantiate the prefab and then initialize the body. To do this you need to call the following after instantiating the object :

Code: [Select]

 Hi Naberius,

I think what you are looking for is the "Index" field of the ParticleSystem. Have you tried setting the Index on each of your particle systems manually in the editor?

LP2D does not use any OnDestroy() methods. Most classes have a Delete() function that you call to remove them from the world. Can you describe what exactly you are doing before the call to  LPAPIBody.CreateBody()?

My guess is that you have not created a world for LPManager to work with causing the crash when you attempt to create a body. The world is created in the LPManager's Awake() function. So make sure that this function is being called before trying to create any bodies.

By the way is there any particular reason why you don't just load a new scene? It seems much simpler if you are removing everything from the scene anyway.

General support for Liquid Physics 2D / Re: Destroy a single particle
« on: November 20, 2015, 01:00:03 pm »
Yeah that sounds like a bug. If it doesn't react to collisions then it is most likely a bug in the drawer. What version of the plugin are you using? If you're not on the latest version try updating.

If you examine one of the drawing classes(eg. WeightAndColorDrawer) you will see something like this :
Code: [Select]
if (i > partdata.Count - 1)
                particles[i].energy = 0f;

This is where it sets any particles that are not used to appear offscreen. Make sure that section of code is reached. You could also try setting the position of the particle to be offscreen.

I'll have to look into this and get back to you. I haven't been able to reproduce the problem yet.

General support for Liquid Physics 2D / Re: Destroy a single particle
« on: November 19, 2015, 02:30:57 pm »
I think you missed this part of Brian's post so I'll just quote him here:

One important thing to note is that the 1st member of the array must be the number of particles you wish to do stuff to. So to destroy the particle with index 27 you'd pass in an array like this  {1,27}
To destroy particle 27 and 28 you'd pass in {2,27,28}

So your line of code should be :
Code: [Select]
LPAPIParticles.DestroySelectedParticles(sysPtr, new[] { 1, pf.ParticleIndex });Where 1 is the count of particles you wish to destroy. However in this case there is actually a better solution. Instead of calling LPAPIParticles.DestroySelectedParticles() repeatedly(which is expensive because it calls into native code), you can just create an array containing all the indices and call DestroySelectedParticles() once.

Something like this, not that this is untested:
Code: [Select]
// create an indices array with the number of indices plus 1
int[] indices = new int[PhysicsManager.ContactListener.ParticleFixtureContacts.Length + 1];
indices[0] = PhysicsManager.ContactListener.ParticleFixtureContacts.Length;

for (int i = 0; i < PhysicsManager.ContactListener.ParticleFixtureContacts.Length; i++)
       indices[i + 1] = pf.ParticleIndex;

var particleSystem = PhysicsManager.ParticleSystems[pf.ParticleSystemIndex];
IntPtr sysPtr = particleSystem.GetPtr();

LPAPIParticles.DestroySelectedParticles(sysPtr, indices);

Yeah this sounds possible with LP2D. However you will have to manages all of the tiles yourself. For example you will need to write your own system to load the liquid for a tile.

Everything is instantiated at start-up and simply hidden and pulled from a pre-fab pool when needed, often altered right after being activated. Would I be able to do this with the water system? For example, say a specific tile (the world is tile-based) has X units of water, can I activate a prefab at that location and set its particle count?

Yes you can create a particle group with whatever position, shape, size and number of particles you like(keep in mind though that all particles have the same radius).

Likewise, would there be a way to keep track of particles, so I can spawn them again when the user goes back to a part of the world that has changed? I was thinking I could use one of the prefabs that deletes particles and set it off-camera (where the world stops) and count the number of particles that were deleted and store that information. Then when the player enters that area again, I can read the data for that grid and spawn the appropriate  amount of particles off-screen.

This is possible but at the moment there is no built in way to do this. You will have to write your own manager to achieve this. The basic idea would be to spawn your initial particle group and let the user interact with the tile. Then when the tile moves off camera you will have to loop over all of the particles which are off screen and remove them, storing their properties (positions/velocities/etc) into the tile data structure. Then when the user moves back to the location you will need to loop over each particle and spawn it back into the system(using LPAPIParticles.CreateParticleInSystem)

How difficult this will be depends on how accurate you want the result to be. You might be able to get away with spawning the particles in the correct position, forgetting about forces and velocities, and just let them settle before they appear onscreen.

I watched the tutorial about querying, and you said that querying particles is expensive. I figured I could make all water particles have 2 particle types. Standard particles and "query particles". For every 50-100 (or whatever) standard particles, there would be a query particle - just to cut down the overhead. I don't need it to be exact or to preserve the physics data, just a "somewhat" close count.

I'm not exactly sure what you mean here by "query particle" and "standard particle". The particles system won't know what type of particles are in a region until the region is queried. So tagging some as query particles will make no difference.

As of version 1.5 though region querying is a lot more efficient. It now uses Box2d's region querying system which uses AABB and spatial partitioning to make the query work a lot faster. (GetParticlesInShape() is the function you're interested in)

I also noticed most of the colliders used in the tutorials were static, but due to the structure of my game, I'm using all dynamic objects. I'd have to attach your system's colliders to my world-objects in place of their standard colliders. Would there be problems with this?
Yes you will need to replace all unity colliders and anything else physics related with our colliders and physics. There will be no problem using dynamic objects no. However keep in mind that static fixtures are a lot more efficient and you should be using them where possible. If the fixtures are being used for terrain(and therefore don't move) they should be static, as making them dynamic will be a waste of resources.

I apologize for the lengthy question, but your system looks really cool and might work really well in my game and save me a lot of time, with much better results.
No problem! I hope our plugin will suit your needs.

General support for Liquid Physics 2D / Re: Multiple metaballs?
« on: November 06, 2015, 01:15:55 pm »
There are a few different ways to achieve something like this. You could use multiple metaball renderers(one for each color) and write a custom shader that adds an outline to each liquid. To do this you would want to look at the existing metaball renderer where the thresholding cuts off anything below a certain alpha value. You can add a few lines here that extend the threshold and change the color to an outline.

Something like :

Code: [Select]
       if(finalColor.a < _botmcut)
if(finalColor.a < _botmcut - outlineAmmount)
finalColor = half4(1,1,1,1);
finalColor.a = 0; 
finalColor.a *= _constant; 

This will work fine but it is not the most efficient way of doing it because of the multiple passes for each colored liquid. You could try to write a shader that adds the lines to the metaballs by detecting pixels that are a mix of the colors of your liquid and shade them as outlines. Basically draw all the colors to the one rendertexture, any liquid colors that overlap another color will have a blended mix of two different colors. You can just set these pixels to white.

The pseudo code for the shader :
Code: [Select]
pixelColor = tex2D (_MainTex, i.uv);
bool didMatchColor = false;
foreach(Color c in liquidColors)
    if( abs(length(c - pixelColor)) < someTheshold)
        didMatchColor = true;

    pixelColor  = fixed4(1,1,1,1);

General support for Liquid Physics 2D / Re: Controlling separate particles?
« on: November 06, 2015, 12:57:45 pm »
There is one major problem with the approach you have outlined. In  LP2D and liquidfun you cannot have variable sized particles. All particles in a particle system must have the same radius. So you wont be able to take mass from one particle and add it to another. However you might be able to design the game so that the bubbles are made up of lots of smaller particles with elastic/jelly like connections between them. Whenever a bubble moves or collides with another bubble you can disconnect the particles from the bubble and then add forces to them.

1) Having a controller for each particle would not be very efficient. But yes particles can be controlled separately, you can apply forces to them to move them around.
2) "calculate the intersection properties and change bubbles diameters respectively." This sounds like something that would be much better suited to a circle collider than a collection of particles.
3) Again this is possible except for changing the size of the particles. You can spawn particles and apply forces to move the bubble but they would have to remain a constant size.
4) Particles in LP2D are completely customizable. You can replace the existing drawers with whatever you want. There are a number of examples included which demonstrate some different techniques for drawing. You can drop in your own shader to replace one of the existing ones.

Code: [Select]
    #region CreateParticleSystem3
    [DllImport ("__Internal")]   
    public static extern IntPtr CreateParticleSystem3(IntPtr worldPointer, float radius, float damping, float gravityScale, int userData,
   float pressureStrength, float viscousStrength,float surfaceTensionPressureStrength,
   float surfaceTensionNormalStrength,float repulsiveStrength,float powderStrength,
   float ejectionStrength, float staticPressureStrength,float staticPressureRelaxation, float colorMixingStrength);
    #endregion CreateParticleSystem3

Sorry the function call should appear as it is above. There is no float32 type in C# so that is why you got errors. Those values are the values used to initialize the particle system, colmixstr being the one you are interested in. Some of those values are set in the LPParticelSystem class and you can look at that class for appropriate valeus. The ones that are not there are explained here :



"If only one of the two colliding particles is a color-mixing one, the other particle retains its pre-collision color."
Have a look at the page linked above and scroll down to the section on color mixing. All particles contribute to the color mixing, however only those with color mixing enabled will actually have their colors changed.

I think the problem is as you described. The color mixing particle is in contact with a number of other particles each of which contributes to its color. So for example if you have a number of black non-color mixing particle surrounding a colored particle, then the colored one will lose its color and become darker. The color will be darkened by each of the black particles in contact. In the next frame the non-color particles will still be black because they didn't absorb any of the color and so they will once again darken the colored ones.

The color mixing does not occur when the mixing flag is turned off. Finally there is a way to change the color mixing strength but you will have to modify one of the api functions to access it. You will need to add the following code to LPAPIParticleSystems.cs :

Code: [Select]
#region CreateParticleSystem3
[DllImport ("__Internal")]   
[DllImport ("liquidfundll")]
public static extern IntPtr CreateParticleSystem3(void* worldPointer, float32 radius, float32 damping, float32 gravityScale, int32 userData, float32 presstr, float32 viscstr,float32 tenpres,float32 tennorm,float32 repulstr,float32 powstr,float32 ejectstr, float32 statpresstr,float32 statpresrelax, float32 colmixstr);
#endregion CreateParticleSystem3

Then in the LPManager script you want to change the call to CreateParticleSystem() to the new call CreateParticleSystem3();

News / Re: Physical Liquid's new game!
« on: October 12, 2015, 12:47:27 pm »
Sorry we can't share the source code for our projects but we are happy to help with your project. The bird in blob-e bird is made up of an elastic particle group which gives it the deform-able quality. We then use the particle destroyer prefab on the ground and on the cactus. When the bird hits the destroyer a portion of the particles are removed making the blob smaller.

Request Features / Re: Apply individual forces to particles
« on: October 12, 2015, 12:41:24 pm »
Hey RunSwimFly,
Sorry it took so long to get back to you but we have been very busy here. Yeah that is a good idea I will expose a function to set UserData using an array as well. This would be useful for a number of different things. I'll look into doing the same for Colors as well which might be useful.

General support for Liquid Physics 2D / Re: How to pause particle system
« on: October 12, 2015, 12:29:11 pm »
Hey spacewalker,
Ill add b2ParticleSystem::SetPaused to the api for the next release.

Pages: [1] 2 3 ... 14