Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Cloth to simulate slime
#22
(22-09-2018, 02:17 PM)josemendez Wrote: Use a mesh that's not a flat plane, but has some folds. The one you show here should work fine. However, make sure that your export it with unit scale. (scale = <1,1,1>). 99% of the issues I see regarding exploding cloth are because the mesh has a random scale value, and the topology has a completely different one. The easiest way to get consistent scaling from your 3D package->Unity->Obi is to just use unit scale.

This seems to have solved the glitch issue! Thanks for your useful advice. I'm pretty close to finishing this.

Also, you mentioned in your previous post about using a radial function to represent a finger press. Could you shed some light on that?

Specifically, where is the part in the ObiClothPicker script which attenuates the mesh, starting from the center point of touch towards the outside? I just want to use a radial equation according to the particle's distance from the center.

If I'm majorly missing something about this code, it'd be great if there's a document explaining some method's such as what "cloth.topology.visualMap.Length" does.

Code:
if (Input.GetMouseButton(0))
{

   meshCollider.enabled = true;

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

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

    RaycastHit hitInfo;
    if (meshCollider.Raycast(ray,out hitInfo,100)){

        int[] tris = currentCollisionMesh.triangles;
        Vector3[] vertices = currentCollisionMesh.vertices;

        // find closest vertex in the triangle we just hit:
        int closestVertex = -1;
        float minDistance = float.MaxValue;

        for (int i = 0; i < 3; ++i)
       {
            int vertex = tris[hitInfo.triangleIndex*3+i];
            float distance = (vertices[vertex] - hitInfo.point).sqrMagnitude;
            if (distance < minDistance){
                minDistance = distance;
                closestVertex = vertex;
            }
        }

        // 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);

            if (OnParticlePicked != null){
                Vector3 worldPosition = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, pickedParticleDepth));
                OnParticlePicked(this,new ParticlePickEventArgs(pickedParticleIndex, worldPosition));
            }
        }
    }

   meshCollider.enabled = false;
}
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