Skip to content

Instantly share code, notes, and snippets.

@mstfmrt07
Last active June 19, 2021 13:07
Show Gist options
  • Save mstfmrt07/e7c0dde202916e57ce107be6cfea6e1f to your computer and use it in GitHub Desktop.
Save mstfmrt07/e7c0dde202916e57ce107be6cfea6e1f to your computer and use it in GitHub Desktop.
private void Roll(Direction direction)
{
StartCoroutine(RollToDirection(direction));
}
private IEnumerator RollToDirection(Direction swipeDirection)
{
if(!isRolling)
{
isRolling = true;
float angle = 90f;
Vector3 axis = GetAxis(swipeDirection);
pivot.position = transform.position;
float elapsedTime = 0f;
while (elapsedTime < rollDuration)
{
elapsedTime += Time.deltaTime;
transform.RotateAround(pivot.position, axis, (angle * (Time.deltaTime / rollDuration)));
yield return null;
}
isRolling = false;
}
}
private Vector3 GetAxis(Direction direction)
{
switch (direction)
{
case Direction.Left:
return Vector3.forward;
case Direction.Up:
return Vector3.right;
case Direction.Right:
return Vector3.back;
case Direction.Down:
return Vector3.left;
default:
return Vector3.zero;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment