Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Cloth to simulate slime
#20
(12-09-2018, 04:45 PM)josemendez Wrote: Hi,

There's lots of things off or downright wrong here, most of them related to basic programming concepts or Unity API usage. I'm afraid I cannot offer support beyond this, as it is not Obi-related. However I will try to outline some of the issues to help you out:

Code:
          for (int i = 0; i < Input.touchCount; i++)
          {
              meshCollider.enabled = true;

              GameObject.Destroy(currentCollisionMesh);
              currentCollisionMesh = GameObject.Instantiate(cloth.clothMesh);
              meshCollider.sharedMesh = currentCollisionMesh;
              ....

              meshCollider.enabled = false;
          }
#endif

Here you're destroying and re-creating the mesh collider used for raycast and input detection for each finger. If you have 3 fingers touching the screen, you're destroying and instantiating the entire mesh 3 times per frame. While technically ok, this is terrible for performance. You should start the for loop after creating the mesh just once.

Code:
if (Input.touchCount < 1)
          {
              if (OnParticleReleased != null)
              {
                  Vector3 worldPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, pickedParticleDepth));
                  OnParticleReleased(this, new ParticlePickEventArgs(pickedParticleIndex, worldPosition));
              }

              pickedParticleIndex = -1;
}

Here you're calling OnParticleReleased just once, after the user has lifted all fingers from the screen. This should be called once for each finger that got lifted off.

Code:
// get particle index:
                  if (closestVertex >= 0 && closestVertex < cloth.topology.visualMap.Length)
                  {

                      pickedParticleIndex = cloth.topology.visualMap[closestVertex];
                      pickedParticleDepth = Mathf.Abs((cloth.transform.TransformPoint(vertices[closestVertex]) - Camera.main.transform.position).z);

There's a deeper issue: you should have arrays (pickedParticleIndices[] and pickedParticleDepths[]) to support multitouch, instead of a single variable. How else can you identify each particle when multiple ones are being dragged? The way the code is written, the last finger to touch the screen will overwrite pickedParticleIndex. Only one particle will be picked.

Code:
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

In this line and several others, you're still using Input.mousePosition, mixing it with Input.touchCount. You should use Input.GetTouch(index) instead (see https://docs.unity3d.com/ScriptReference/Touch.html), as the mousePosition returns the average of all finger positions when on a touchscreen (read Unity's documentation), which is precisely the result you're getting.

All that information is very useful, thanks. Again, my coding skills are very basic, apologies if I mixed the thread up with programming questions.

So I've been playing around with various parameters for the slime cloth and as mentioned before, I tried using height, normal and occlusion maps on materials to get the "depth" and "folds" effects.

Nothing I did could reproduce this effect.

As you can see, ignoring the colour and lighting changes, the slime shown here reforms very slowly and creates actual folds in the object. How do I create these "folds"? No amount of material modification seems to help, as what's shown here seems to be true mesh manipulation.

Next, instead of using a flat square plane mesh, I tried out using something like this -


.png   mesh.PNG (Size: 5.93 KB / Downloads: 43)

This is a low poly "rough surface" mesh. I fixed all of it's edge particles, then initialized it as a new cloth. But instead of deforming properly on touch, it creates huge graphical glitches (Infinite stretching on mouse touch, etc).

Is there no way I can reproduce the aforementioned style of slime correctly on cloth objects? I've tried alternating everything, from damping, slack, stretch, etc. but in vain.
Reply


Messages In This Thread
Cloth to simulate slime - by arrnav96 - 09-09-2018, 06:06 AM
RE: Cloth to simulate slime - by josemendez - 09-09-2018, 11:32 AM
RE: Cloth to simulate slime - by arrnav96 - 10-09-2018, 11:17 AM
RE: Cloth to simulate slime - by josemendez - 10-09-2018, 11:41 AM
RE: Cloth to simulate slime - by arrnav96 - 10-09-2018, 11:55 AM
RE: Cloth to simulate slime - by josemendez - 10-09-2018, 01:45 PM
RE: Cloth to simulate slime - by arrnav96 - 10-09-2018, 03:47 PM
RE: Cloth to simulate slime - by josemendez - 10-09-2018, 03:56 PM
RE: Cloth to simulate slime - by arrnav96 - 10-09-2018, 04:03 PM
RE: Cloth to simulate slime - by josemendez - 10-09-2018, 04:05 PM
RE: Cloth to simulate slime - by josemendez - 10-09-2018, 04:27 PM
RE: Cloth to simulate slime - by arrnav96 - 11-09-2018, 09:25 AM
RE: Cloth to simulate slime - by josemendez - 11-09-2018, 10:32 AM
RE: Cloth to simulate slime - by arrnav96 - 11-09-2018, 10:25 PM
RE: Cloth to simulate slime - by josemendez - 12-09-2018, 08:09 AM
RE: Cloth to simulate slime - by arrnav96 - 12-09-2018, 01:01 PM
RE: Cloth to simulate slime - by josemendez - 12-09-2018, 02:26 PM
RE: Cloth to simulate slime - by arrnav96 - 12-09-2018, 03:44 PM
RE: Cloth to simulate slime - by josemendez - 12-09-2018, 04:45 PM
RE: Cloth to simulate slime - by arrnav96 - 19-09-2018, 10:29 PM
RE: Cloth to simulate slime - by josemendez - 22-09-2018, 02:17 PM
RE: Cloth to simulate slime - by arrnav96 - 30-09-2018, 03:35 PM
RE: Cloth to simulate slime - by arrnav96 - 06-10-2018, 03:47 AM
RE: Cloth to simulate slime - by akayashi1212 - 26-03-2021, 10:00 AM
RE: Cloth to simulate slime - by josemendez - 26-03-2021, 11:03 AM
RE: Cloth to simulate slime - by akayashi1212 - 27-03-2021, 04:24 AM
RE: Cloth to simulate slime - by josemendez - 29-03-2021, 09:59 AM
RE: Cloth to simulate slime - by akayashi1212 - 29-03-2021, 11:35 AM
RE: Cloth to simulate slime - by josemendez - 31-03-2021, 10:09 AM
RE: Cloth to simulate slime - by akayashi1212 - 31-03-2021, 02:47 PM
RE: Cloth to simulate slime - by josemendez - 31-03-2021, 06:21 PM
RE: Cloth to simulate slime - by akayashi1212 - 01-04-2021, 03:27 AM
RE: Cloth to simulate slime - by josemendez - 01-04-2021, 08:40 AM
RE: Cloth to simulate slime - by akayashi1212 - 01-04-2021, 09:57 AM
RE: Cloth to simulate slime - by josemendez - 05-04-2021, 12:06 PM
RE: Cloth to simulate slime - by akayashi1212 - 07-04-2021, 03:35 AM