public void Reset() { failLaunch = false; CanProcessNextStep = true; sliderLockOut = false; popup.Reset(); HideGizmoAndWidgets(); if (activeCoroutine != null) { StopCoroutine(activeCoroutine); } foreach (GameObject marker in markers) { Destroy(marker); } markers.Clear(); currentStep = LearningStep.NotStarted; midAirStep = MidAirStep.Undefined; foreach (ArrowIndicator arrow in vectorArrows) { Destroy(arrow.gameObject); } vectorArrows.Clear(); // Reset Camera view transform mainCam.transform.position = catapult.startCamTransform.position; mainCam.transform.rotation = catapult.startCamTransform.rotation; catapult.Reset(); cannonBall.Reset(); cubeWall.Reset(); }
public IEnumerator DoProcessMidAirState_Energy() { Debug.Log("Show transfer of Elastic Potential Energy to Kinetic Energy that Launches the Cannon Ball and Observe Forces while in air"); if (failLaunch) { popup.Show(); yield break; } CanProcessNextStep = false; sliderLockOut = true; // Lockout physics config sliders midAirStep = MidAirStep.Launching; energyWidget.Show(); // Show Kinetic Energy Info float currentKineticEnergy = 0; energyWidget.UpdateKineticEnergy(currentKineticEnergy); // Show Draining of Elastic Potential Energy To Kinetic Energy (Kinetic Energy will equal the Elastic Potential Energy) float kineticEnergy = Kinetic_Energy_At_Launch(); float elasticEnergy = Kinetic_Energy_At_Launch(); const float drainSpeed = 0.05f; // Animate the depletion of Elastic Potential Energy and Gain of Kinetic Energy prior to Launch while (!EEMath.Approximately(elasticEnergy, 0, 0.001f) || !EEMath.Approximately(currentKineticEnergy, kineticEnergy, 0.001f)) { yield return(null); elasticEnergy = Mathf.Lerp(elasticEnergy, 0, drainSpeed); energyWidget.UpdateElasticEnergy(elasticEnergy); currentKineticEnergy = Mathf.Lerp(currentKineticEnergy, kineticEnergy, drainSpeed); energyWidget.UpdateKineticEnergy(currentKineticEnergy); } yield return(StartCoroutine(DoLerpCameraToTransform(catapult.step3CamTransform))); float velocity = Velocity_At_Time_Of_Launch(); float ratio = ratio_Of_DEPE_Over_DGPE(); catapult.ThrowBall(catapult.launchVector.up, velocity); while (!cannonBall.paused) { yield return(null); Transform riseMarker = Utils.CreateMarker(null, 0.1f, Color.red); riseMarker.position = cannonBall.transform.position; markers.Add(riseMarker.gameObject); // Catch when the ball has left max arc height if (cannonBall.rigidBody.velocity.y < 0) { if (!cannonBall.maxHeightReached) { cannonBall.maxHeightReached = true; Transform peakMarker = Utils.CreateMarker(null, 0.2f, Color.blue); peakMarker.position = cannonBall.prevPosition; markers.Add(peakMarker.gameObject); cannonBall.PauseInAir(); yield return(StartCoroutine(DoLerpCameraToTransform(cannonBall.step4CamTransform))); } } } midAirStep = MidAirStep.Maxheight; weightPoint = cannonBall.LeftWeightPoint; resultPoint = catapult.springVector; ArrowIndicator maxHeightVelocityArrow = Instantiate(arrowBasicFrontPivotPrefab).GetComponent <ArrowIndicator>(); maxHeightVelocityArrow.SetArrowTransform(cannonBall.PeakHightVelocityMarker); maxHeightVelocityArrow.bobbing = true; maxHeightVelocityArrow.Show(); vectorArrows.Add(maxHeightVelocityArrow); maxHeightVelocityArrow.infoWidget.UpdateInfoWidget(null, (float)Math.Round(cannonBall.currentVelocity.magnitude, 2), "Velocity", true); energyWidget.AttachToTransform(cannonBall.EnergyWidgetMarker_LeftOffset); energyWidget.infoWidget.ToggleElasticInfo(false); energyWidget.infoWidget.ToggleKineticInfo(false); energyWidget.UpdateGravEnergy(cannonBall.Gravitational_Potential_Energy()); CanProcessNextStep = true; yield return(new WaitUntil(() => { return (midAirStep == MidAirStep.SlopeDown); })); // wait for camera to complete lerping to Ball mid air position CanProcessNextStep = false; HideGizmoAndWidgets(); // Hide all force arrows in preperation for next view step distanceGizmo.Show(); yield return(StartCoroutine(DoLerpCameraToTransform(cannonBall.step5CamTransform))); cannonBall.Resume(); // Cannonball falling downward while (!cannonBall.paused) { Transform downMarker = Utils.CreateMarker(null, 0.1f, Color.green); downMarker.position = cannonBall.transform.position; markers.Add(downMarker.gameObject); yield return(null); RaycastHit hitResult; if (RaycastFromPos(cannonBall.transform.position, -cannonBall.transform.up, Mathf.Infinity, out hitResult, true)) { float diff = cannonBall.transform.position.y - hitResult.point.y; if (diff < DistanceFromGround_At_TimeOFLaunch) { cannonBall.PauseInAir(); } } } yield return(StartCoroutine(DoLerpCameraToTransform(cannonBall.step4CamTransform))); ArrowIndicator slopeDownVelocityArrow = Instantiate(arrowBasicBackPivotPrefab).GetComponent <ArrowIndicator>(); slopeDownVelocityArrow.bobbing = true; vectorArrows.Add(slopeDownVelocityArrow); OrientTransformToVector(ref cannonBall.ResultPoint_Centered, cannonBall.currentVelocity); slopeDownVelocityArrow.SetArrowTransform(cannonBall.ResultPoint_Centered); slopeDownVelocityArrow.Show(); slopeDownVelocityArrow.infoWidget.UpdateInfoWidget(null, (float)Math.Round(cannonBall.currentVelocity.magnitude, 2), "Velocity", true); energyWidget.AttachToTransform(cannonBall.EnergyWidgetMarker_RightOffset); energyWidget.infoWidget.ToggleElasticInfo(false); energyWidget.UpdateGravEnergy(cannonBall.Gravitational_Potential_Energy()); energyWidget.Show(); CanProcessNextStep = true; yield return(new WaitUntil(() => { return (midAirStep == MidAirStep.CompleteArc); })); // wait for camera to complete lerping to Ball mid air position CanProcessNextStep = false; HideGizmoAndWidgets(); distanceGizmo.Show(); yield return(StartCoroutine(DoLerpCameraToTransform(cannonBall.step5CamTransform))); // RE focus camera cannonBall.Resume(); // resume cannon ball trajectory // Draw the rest of the arc markers while (!cannonBall.paused && cannonBall.inAir) { Transform downMarker = Utils.CreateMarker(null, 0.1f, Color.green); downMarker.position = cannonBall.transform.position; markers.Add(downMarker.gameObject); yield return(null); } cannonBall.transform.rotation = Quaternion.identity; midAirStep = MidAirStep.Undefined; // Mid air step is over; // Freeze the ball's movement and rotation as soon as it makes contact with the ground; cannonBall.transform.rotation = Quaternion.identity; cannonBall.rigidBody.constraints = RigidbodyConstraints.FreezeAll; // Cheat to make Cannonball touch ground cannonBall.transform.position = new Vector3(cannonBall.transform.position.x, 0.425f, cannonBall.transform.position.z); yield return(StartCoroutine(DoProcessStoppedState_Energy())); activeCoroutine = null; }
public IEnumerator DoProcessMidAirState_Forces() { sliderLockOut = true; // Ensure that we cannot manipulate physics attributes after launch Debug.Log("Launch Cannon Ball and Observe Forces while in air"); if (failLaunch) { popup.Show(); yield break; } HideGizmoAndWidgets(); distanceGizmo.Show(); CanProcessNextStep = false; midAirStep = MidAirStep.Launching; yield return(StartCoroutine(DoLerpCameraToTransform(catapult.step3CamTransform))); float velocity = Velocity_At_Time_Of_Launch(); float ratio = ratio_Of_DEPE_Over_DGPE(); catapult.ThrowBall(catapult.launchVector.up, velocity); while (!cannonBall.paused) { yield return(null); Transform riseMarker = Utils.CreateMarker(null, 0.1f, Color.red); riseMarker.position = cannonBall.transform.position; markers.Add(riseMarker.gameObject); // Catch when the ball has left max arc height if (cannonBall.rigidBody.velocity.y < 0) { if (!cannonBall.maxHeightReached) { cannonBall.maxHeightReached = true; Transform peakMarker = Utils.CreateMarker(null, 0.2f, Color.blue); peakMarker.position = cannonBall.prevPosition; markers.Add(peakMarker.gameObject); cannonBall.PauseInAir(); yield return(StartCoroutine(DoLerpCameraToTransform(cannonBall.step4CamTransform))); } } } //yield return new WaitUntil(() => { return !camLerping; }); // wait for camera to complete lerping to Ball mid air position midAirStep = MidAirStep.Maxheight; weightPoint = cannonBall.LeftWeightPoint; resultPoint = catapult.springVector; ArrowIndicator maxHeightVelocityArrow = Instantiate(arrowBasicFrontPivotPrefab).GetComponent <ArrowIndicator>(); maxHeightVelocityArrow.SetArrowTransform(cannonBall.PeakHightVelocityMarker); maxHeightVelocityArrow.bobbing = true; maxHeightVelocityArrow.Show(); vectorArrows.Add(maxHeightVelocityArrow); maxHeightVelocityArrow.infoWidget.UpdateInfoWidget(null, (float)Math.Round(cannonBall.currentVelocity.magnitude, 2), "Velocity", true); gravArrow.SetArrowTransform(cannonBall.CenterWeightPoint); gravArrow.Show(); CanProcessNextStep = true; yield return(new WaitUntil(() => { return (midAirStep == MidAirStep.SlopeDown); })); // wait for camera to complete lerping to Ball mid air position CanProcessNextStep = false; HideGizmoAndWidgets(); // Hide all force arrows in preperation for next view step distanceGizmo.Show(); yield return(StartCoroutine(DoLerpCameraToTransform(cannonBall.step5CamTransform))); cannonBall.Resume(); // Cannonball falling downward while (!cannonBall.paused) { Transform downMarker = Utils.CreateMarker(null, 0.1f, Color.green); downMarker.position = cannonBall.transform.position; markers.Add(downMarker.gameObject); yield return(null); RaycastHit hitResult; if (RaycastFromPos(cannonBall.transform.position, -cannonBall.transform.up, Mathf.Infinity, out hitResult, true)) { float diff = cannonBall.transform.position.y - hitResult.point.y; if (diff < DistanceFromGround_At_TimeOFLaunch) { cannonBall.PauseInAir(); } } } yield return(StartCoroutine(DoLerpCameraToTransform(cannonBall.step4CamTransform))); gravArrow.SetArrowTransform(cannonBall.CenterWeightPoint); gravArrow.Show(); ArrowIndicator slopeDownVelocityArrow = Instantiate(arrowBasicBackPivotPrefab).GetComponent <ArrowIndicator>(); slopeDownVelocityArrow.bobbing = true; vectorArrows.Add(slopeDownVelocityArrow); OrientTransformToVector(ref cannonBall.ResultPoint_Centered, cannonBall.currentVelocity); slopeDownVelocityArrow.SetArrowTransform(cannonBall.ResultPoint_Centered); slopeDownVelocityArrow.Show(); slopeDownVelocityArrow.infoWidget.UpdateInfoWidget(null, (float)Math.Round(cannonBall.currentVelocity.magnitude, 2), "Velocity", true); CanProcessNextStep = true; yield return(new WaitUntil(() => { return (midAirStep == MidAirStep.CompleteArc); })); // wait for camera to complete lerping to Ball mid air position CanProcessNextStep = false; HideGizmoAndWidgets(); distanceGizmo.Show(); yield return(StartCoroutine(DoLerpCameraToTransform(cannonBall.step5CamTransform))); // RE focus camera cannonBall.Resume(); // resume cannon ball trajectory // Draw the rest of the arc markers while (!cannonBall.paused && cannonBall.inAir) { Transform downMarker = Utils.CreateMarker(null, 0.1f, Color.green); downMarker.position = cannonBall.transform.position; markers.Add(downMarker.gameObject); yield return(null); } yield return(new WaitUntil(() => { return (cannonBall.rigidBody.velocity == Vector3.zero); })); // wait for camera to complete lerping to Ball mid air position CanProcessNextStep = true; cannonBall.transform.rotation = Quaternion.identity; midAirStep = MidAirStep.Undefined; // Mid air step is over; activeCoroutine = null; }