Last active
June 19, 2021 14:03
-
-
Save mstfmrt07/6da0ad1e7fdd3618af0dc4527757e577 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Transform ghostPlayer; | |
private IEnumerator RollToDirection(Direction swipeDirection) | |
{ | |
if (!isRolling) | |
{ | |
isRolling = true; | |
float angle = 90f; | |
Vector3 axis = GetAxis(swipeDirection); | |
Vector3 directionVector = GetDirectionVector(swipeDirection); | |
Vector2 pivotOffset = GetPivotOffset(swipeDirection); | |
pivot.position = transform.position + (directionVector * pivotOffset.x) + (Vector3.down * pivotOffset.y); | |
//simulate before the action in order to get an ideal result | |
CopyTransformData(transform, ghostPlayer); | |
ghostPlayer.RotateAround(pivot.position, axis, angle); | |
float elapsedTime = 0f; | |
while (elapsedTime < rollDuration) | |
{ | |
elapsedTime += Time.deltaTime; | |
transform.RotateAround(pivot.position, axis, (angle * (Time.deltaTime / rollDuration))); | |
yield return null; | |
} | |
CopyTransformData(ghostPlayer, transform); | |
isRolling = false; | |
} | |
} | |
public void CopyTransformData(Transform source, Transform target) | |
{ | |
target.localPosition = source.localPosition; | |
target.localEulerAngles = source.localEulerAngles; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment