Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Stick" rigidbodies to softbody
#5
Okay I tried what you said.

It did kinda worked what I wanted, but some of the spheres are inside the softbody whereas some are outside floating in air.

Code:
Component contactObject;
if (ObiCollider.idToCollider.TryGetValue(e.contacts.Data[i].other, out contactObject))
{
    if (contactObject != null)
    {
        if (contactObject.gameObject.CompareTag("Glitter"))
        {
            Glitter glitterInstance = contactObject.gameObject.GetComponent<Glitter>();
            if(glitterInstance != null)
            {
                if(!glitterInstance.isAttached)
                {
                    glitterInstance.isAttached = true;
                    glitterInstance.glitterRigidbody.isKinematic = true;
                    glitterInstance.glitterObiCollider.Phase = 1;
                    glitterInstance.particleIndex = e.contacts.Data[i].particle;
                    glitterInstance.particleAttachOffset = slimeActor.GetParticlePosition(glitterInstance.particleIndex) - (Vector3)e.contacts.Data[i].point;

                    if (!glittersList.Contains(glitterInstance))
                        glittersList.Add(glitterInstance);
                }
            }                               
        }
    }
}

private void HandleGlitters()
{
    if (glittersList.Count <= 0)
        return;

    for (int i = 0; i < glittersList.Count; i++)
    {
        var particlePos = slimeActor.GetParticlePosition(glittersList[i].particleIndex);
        glittersList[i].transform.position = particlePos - glittersList[i].particleAttachOffset;
        //glittersList[i].SetPosition(Pos);
    }
}

HandleGlitters() is called in update method.

Sorry I am still noob in coding. Am I doing something wrong here?

I have attached a screenshot.
   
Reply


Messages In This Thread
"Stick" rigidbodies to softbody - by Spectra_7 - 07-05-2021, 10:08 AM
RE: "Stick" rigidbodies to softbody - by Spectra_7 - 07-05-2021, 01:31 PM