Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private IEnumerator routineRollCube() {
- float rotateAmount = 90.0f;
- Vector3 delta = new Vector3(rotateAmount, 0f, 0f);
- Vector3 axis = Vector3.left;
- Vector3 currentPivot = _pivotList[_pivotIndex].transform.position;
- float initialDuration = _gameManager.RollDuration;
- float warpedDuration = _gameManager.RollDuration;
- var reachedHalfPoint = false;
- var isOnTile = true;
- float startTime = Time.time;
- float endTime = startTime + warpedDuration;
- float oldY = colliderGo.transform.position.y;
- Vector3 translateVector = new Vector3(0, 0, 0);
- Quaternion rotationFinish = modelGo.transform.rotation * Quaternion.Euler(new Vector3(-rotateAmount, 0f,0f));
- Vector3 positionFinish = modelGo.transform.position;
- positionFinish.z -= 1f;
- desolidifyIfWaterCube();
- _rollPercentage = 0f;
- while (true) {
- while (_gameManager.isPaused) {
- yield return null;
- }
- warpedDuration += (initialDuration) - (warpedDuration * 0.5f); // todo; pull from time warp
- _rollPercentage = (Time.time - startTime) / warpedDuration;
- if (_rollPercentage > 1f) {
- break;
- }
- float angle = rotateAmount * (Time.deltaTime / warpedDuration);
- // Check to see if cube is out of bounds, or current tile is no longer active
- if (currentTile == null || !currentTile.isInPlay) {
- fallIfNeeded();
- IsBusy = false;
- yield break;
- }
- isOnTile = _gameManager.TileHasNextTile(currentTile);
- if (!isOnTile) {
- //Debug.Log("is not on tile");
- }
- // Check to see if cube was removed
- if (!mIsInActiveCubes) {
- IsBusy = false;
- yield break;
- }
- // Move cube to next tile if at half point
- if (!reachedHalfPoint && _rollPercentage >= 0.5f) {
- // If next tile does not exist, then trigger a fall
- if (!_gameManager.TileHasNextTile(currentTile)) {
- fallIfNeeded();
- IsBusy = false;
- yield break;
- }
- _gameManager.AddMoveCubeToTile(GameBoard.Direction.DOWN, currentTile);
- reachedHalfPoint = true;
- }
- modelGo.transform.RotateAround(currentPivot, axis, angle);
- // Translation
- translateVector = modelGo.transform.position;
- translateVector.y = oldY;
- colliderGo.transform.position = translateVector;
- yield return null;
- }
- _rollPercentage = -1f;
- _isRolling = false;
- _gameManager.OnCubeFinishedRolling(this);
- //Debug.Log("cube.isActivelyRolling = false");
- modelGo.transform.rotation = rotationFinish;
- modelGo.transform.position = positionFinish;
- _pivotIndex = getNextPivotIndex();
- // Check to see if cube is out of bounds
- if (currentTile == null) {
- fallIfNeeded();
- } else {
- IsBusy = false;
- }
- yield break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement