Possible Alternative for Detecting Settled Pins

I just spent a couple of minutes coming up with this alternative to detecting if pins have settled. I haven’t had time to fully test all potential issues with it, so if you want to try it out then feel free and let me know if you find anything wrong with it.

Note that this is all inside of the PinSetter class:
(pinsSettledCalled is to keep update from invoking the CheckPinsSettled method 60+ times)

private bool ballInBox = false;
private bool pinsSettled = false;
private bool pinsSettledCalled = false;

void Update () {
	if (ballInBox && !pinsSettled && !pinsSettledCalled) {
		pinsSettledCalled = true;
		Invoke ("CheckPinsSettled", 3);
	}
}

void CheckPinsSettled () {
	foreach (Pin pin in GameObject.FindObjectsOfType<Pin> ()) {
		Vector3 pinVelocity = pin.gameObject.GetComponent<Rigidbody> ().velocity;
		Vector3 pinAngularVelocity = pin.gameObject.GetComponent<Rigidbody> ().angularVelocity;

		if (pinVelocity.x != 0 || pinVelocity.y != 0 || pinVelocity.z != 0 || pinAngularVelocity.x != 0 || pinAngularVelocity.y != 0 || pinAngularVelocity.z != 0) {
			pinsSettledCalled = false;
			return;
		}
	}
	pinsSettled = true;
	StandingPinCount ();
}

Privacy & Terms