public void AddNewBall() { _ballGenerator.GenerateNewBall(); }
// Update is called once per frame void Update() { // If the ball rolled away, do not do any extra collision detections if (objectWanderedAway) { return; } //***************************************** // Detect object's collision with user's fingers handFrame = provider.CurrentFrame; collisionRefreshTimer -= Time.deltaTime; if (collisionRefreshTimer <= 0) { collisionRefreshTimer = collisionRefreshInterval; foreach (Hand hand in handFrame.Hands) { foreach (Finger finger in hand.Fingers) { Bone bone0 = finger.Bone(Bone.BoneType.TYPE_DISTAL); Bone bone1 = finger.Bone(Bone.BoneType.TYPE_INTERMEDIATE); Bone bone2 = finger.Bone(Bone.BoneType.TYPE_PROXIMAL); Bone bone3 = finger.Bone(Bone.BoneType.TYPE_METACARPAL); Vector3 bone0Center = bone0.Center.ToVector3(); Vector3 bone1Center = new Vector3(0, 0, 0); if (finger.Type != Finger.FingerType.TYPE_THUMB) { bone1Center = bone1.Center.ToVector3(); } Vector3 bone2Center = bone2.Center.ToVector3(); Vector3 bone3Center = bone3.Center.ToVector3(); float[] distToBones = new float[4] { 100, 100, 100, 100 }; distToBones[0] = (bone0Center - currTransform.position).sqrMagnitude; distToBones[1] = (bone1Center - currTransform.position).sqrMagnitude; distToBones[2] = (bone2Center - currTransform.position).sqrMagnitude; distToBones[3] = (bone3Center - currTransform.position).sqrMagnitude; Finger.FingerType type = finger.Type; int fingerIndex = ConvertFingerTypeToIndex(type); for (int i = 0; i < distToBones.Length; ++i) { if (distToBones[i] < ballRadius) { float depthPercentage = (ballRadius - distToBones[i]) / ballRadius; StimulateFingerSegment(fingerIndex, i, 1, depthPercentage); MotorConstraint(fingerIndex, i, true, depthPercentage); } else { EndStimulationForFingerSegment(fingerIndex, i); EndMotorConstraint(fingerIndex, i); } } } } } //***************************************** // Generating new ball //Detecting changes in object's position float movedDistance = Vector3.Distance(currTransform.position, initialPosition); if (movedDistance > 1.0F && !nextBallGenerated) { ballGenerator.GenerateNewBall(initialPosition); nextBallGenerated = true; } if (movedDistance > 5.0F) { objectWanderedAway = true; } }