void OnTriggerEnter(Collider other) { compoundObstacleHandler = gameObject.GetComponentInParent <CollisionOnCompoundObstacle>(); experimentLogger = experimentController.GetComponent <ExperimentDataLogger>(); if (other.gameObject.CompareTag("targetObject")) //Collision with grasped object { if (compoundObstacleHandler != null) //compound obstacle { if (compoundObstacleHandler.GetCollisionsWithGraspedObject() == 0) // only the first enter causes a collision count { UpdateGlobalErrorCount(other.name); } experimentLogger.SetColliding(true); compoundObstacleHandler.IncreaseCollisionsWithGraspedObject(); } else // simple obstacle { graspedObjectIsCollidingWithObstacle = true; UpdateGlobalErrorCount(other.name); experimentLogger.SetColliding(true); } if (visualizeCollisions) { rend.material.color = Color.red; } } else if (other.gameObject.CompareTag("gripper")) //Collision with robot { if (compoundObstacleHandler != null) //compound obstacle { if (compoundObstacleHandler.GetCollisionsWithGripper() == 0) // only the first enter causes a collision count { if (experimentLogger.IsGrabbed()) { UpdateGripperCollisionCount(other.name); } } experimentLogger.SetColliding(true); compoundObstacleHandler.IncreaseCollisionsWithGripper(); } else //simple obstacle { { if (gripperCollisionCount == 0) { if (experimentLogger.IsGrabbed()) { UpdateGripperCollisionCount(other.name); //causes counting collision } } gripperCollisionCount++; experimentLogger.SetColliding(true); //causes haptic feedback } } } }
// Use this for initialization void Start() { rend = GetComponent <Renderer>(); originalColor = rend.material.color; gripperCollisionCount = 0; graspedObjectIsCollidingWithObstacle = false; compoundObstacleHandler = null; experimentController = GameObject.Find("ExperimentController"); tcp = GameObject.Find("TCP"); targetObject = GameObject.FindGameObjectWithTag("targetObject"); collisionRecorder = experimentController.GetComponent <RecordCollisions>(); }
private void OnTriggerExit(Collider other) { compoundObstacleHandler = gameObject.GetComponentInParent <CollisionOnCompoundObstacle>(); if (visualizeCollisions) { rend.material.color = originalColor; } if (other.gameObject.CompareTag("targetObject")) { if (compoundObstacleHandler != null) //compound obstacle { compoundObstacleHandler.DecreaseCollisionsWithGraspedObject(); if (compoundObstacleHandler.GetCollisionsWithGripper() == 0 && compoundObstacleHandler.GetCollisionsWithGraspedObject() == 0 && gripperCollisionCount == 0) { experimentLogger.SetColliding(false); } } else // simple obstacle { graspedObjectIsCollidingWithObstacle = false; if (gripperCollisionCount == 0) { experimentLogger.SetColliding(false); } } } else if (other.gameObject.CompareTag("gripper")) { if (compoundObstacleHandler != null) //compound obstacle { compoundObstacleHandler.DecreaseCollisionsWithGripper(); if (compoundObstacleHandler.GetCollisionsWithGripper() == 0 && compoundObstacleHandler.GetCollisionsWithGraspedObject() == 0 && gripperCollisionCount == 0) { experimentLogger.SetColliding(false); } } else { gripperCollisionCount--; if (gripperCollisionCount == 0 && !graspedObjectIsCollidingWithObstacle) { experimentLogger.SetColliding(false); } } } }