daily pastebin goal
87%
SHARE
TWEET

Cube Rotation

a guest Mar 14th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  private IEnumerator SmoothMove(TileController tile, TileController.MoveDirection direction) {
  2.         Quaternion startRotation = VisiualGridObject.rotation;
  3.         Quaternion targetRotation = VisiualGridObject.rotation;
  4.  
  5.         switch (direction.Value) {
  6.             case TileController.MoveDirection.Direction.Left: {
  7.                 targetRotation = Quaternion.LookRotation(Vector3.forward, Vector3.left);
  8.                 break;
  9.             }
  10.             case TileController.MoveDirection.Direction.Up: {
  11.                 targetRotation = Quaternion.LookRotation(Vector3.down, Vector3.forward);
  12.                 break;
  13.             }
  14.             case TileController.MoveDirection.Direction.Right: {
  15.                 targetRotation = Quaternion.LookRotation(Vector3.forward, Vector3.right);
  16.                 break;
  17.             }
  18.             case TileController.MoveDirection.Direction.Down: {
  19.                 targetRotation = Quaternion.LookRotation(Vector3.up, Vector3.back);
  20.                 break;
  21.             }
  22.         }
  23.  
  24.         Vector3 startPosition = transform.position;
  25.         Vector3 targetPosition = tile.transform.position + Vector3.up * transform.localScale.x;
  26.  
  27.         GridPosition = tile.GridPosition;
  28.         tile.CurrentObject = this;
  29.  
  30.         float timer = 0.2f;
  31.  
  32.         CanMove = false;
  33.  
  34.         AnimationCurve curve = AnimationCurve.EaseInOut(0,0,1,0);
  35.         curve.AddKey(new Keyframe(0.5f, 1));
  36.  
  37.         while (timer > 0) {
  38.  
  39.             VisiualGridObject.rotation = Quaternion.Lerp(startRotation, targetRotation, (0.2f - timer) * 5);
  40.             transform.position = Vector3.Lerp(startPosition, targetPosition, (0.2f - timer) * 5);
  41.  
  42.             timer -= Time.deltaTime * curve.Evaluate((0.2f - timer) * 5) + 0.01f;
  43.             yield return null;
  44.         }
  45.  
  46.         VisiualGridObject.rotation = Quaternion.identity;
  47.         transform.position = targetPosition;
  48.  
  49.         CanMove = true;
  50.  
  51.         yield return null;
  52.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top