I found the solution. In case anyone wondering or reading this forum idk can apply this solution. Again the case was reaching each finger collision event with objects.
Actually changing a few code in "Interaction Hand" script created the solution. I wrote a script which handles fingerCollisions.
public class fingerCollisionScript : MonoBehaviour
{
public int boneIndex;
private fingerCollisionController controller;
private bool collisionOccured;
private Collider collidedObject;
private Collider m_Collider;
// Start is called before the first frame update
void Start()
{
GameObject controllerObj = GameObject.FindGameObjectWithTag("fingerCollisionController");
m_Collider = this.GetComponent<Collider>();
if (controllerObj)
{
controller = controllerObj.GetComponent<fingerCollisionController>();
} else
{
Debug.LogError("fingerCollisionController could not be found");
}
}
// Update is called once per frame
void Update()
{
if (collisionOccured && !m_Collider.bounds.Intersects(collidedObject.bounds))
{
Debug.Log("Bounds intersecting");
controller.boneNotCollided(boneIndex);
collisionOccured = false;
}
}
public void setIndex(int index)
{
boneIndex = index;
}
public void OnTriggerEnter(Collider collision)
{
controller.boneCollided(boneIndex);
collisionOccured = true;
collidedObject = collision;
}
}
and then added these lines into interactionHand Script:
contactBoneObj.transform.position = bone.Center.ToVector3();
contactBoneObj.transform.rotation = bone.Rotation.ToQuaternion();
// Custom: adding fingerCollisionScript
contactBoneObj.AddComponent<fingerCollisionScript>();
contactBoneObj.GetComponent<fingerCollisionScript>().setIndex(boneArrayIndex);
Index(boneArrayIndex);
And finally wrote a controller which handles the colliding situation of each bone.
public void boneCollided(int boneIndex)
{
boneArray[boneIndex] = 1;
int[] motorsToTurnOn = boneMotorMap[boneIndex];
for(int m=0; m <motorsToTurnOn.Length; m++)
{
motorArray[motorsToTurnOn[m]] = 255;
}
}
public void boneNotCollided(int boneIndex)
{
boneArray[boneIndex] = 1;
int[] motorsToTurnOn = boneMotorMap[boneIndex];
for (int m = 0; m < motorsToTurnOn.Length; m++)
{
motorArray[motorsToTurnOn[m]] =0;
}
}
You are welcome