|
@ -134,17 +134,16 @@ public class Character : MonoBehaviour |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerator RotateToDirection(Direction direction, Animation animation, float time, bool isLocal = true) |
|
|
|
|
|
|
|
|
public IEnumerator RotateInDirection(Direction direction,float angles, Animation animation, float time) |
|
|
{ |
|
|
{ |
|
|
System.Func<float, float> yFunction = null; |
|
|
System.Func<float, float> yFunction = null; |
|
|
if (animation == Animation.Jump) |
|
|
if (animation == Animation.Jump) |
|
|
yFunction = (t) => Mathf.Sin((Mathf.PI * t)); |
|
|
yFunction = (t) => Mathf.Sin((Mathf.PI * t)); |
|
|
|
|
|
|
|
|
Vector3 _endDir = isLocal ? direction.ToVector(transform) : direction.ToVector(); |
|
|
|
|
|
|
|
|
|
|
|
StartAnimation(animation, time); |
|
|
StartAnimation(animation, time); |
|
|
|
|
|
|
|
|
yield return StartCoroutine(LerpToRotation(_endDir, time * 0.8f, yFunction)); |
|
|
|
|
|
|
|
|
Debug.Log("Rotating by: " + angles); |
|
|
|
|
|
yield return StartCoroutine(Rotate(direction,angles, time * 0.8f, yFunction)); |
|
|
|
|
|
|
|
|
StopAnimation(animation); |
|
|
StopAnimation(animation); |
|
|
} |
|
|
} |
|
@ -158,6 +157,9 @@ public class Character : MonoBehaviour |
|
|
Vector3 _newPos; |
|
|
Vector3 _newPos; |
|
|
|
|
|
|
|
|
float elapsedTime = 0; |
|
|
float elapsedTime = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (elapsedTime / time < 1) |
|
|
while (elapsedTime / time < 1) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
@ -180,34 +182,50 @@ public class Character : MonoBehaviour |
|
|
transform.position = _newPos; |
|
|
transform.position = _newPos; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private IEnumerator LerpToRotation(Vector3 target, float time, System.Func<float, float> heightOffset = null) |
|
|
|
|
|
|
|
|
private IEnumerator Rotate(Direction direction, float angles, float time, System.Func<float, float> heightOffset = null) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
Vector3 _startDir = transform.forward; |
|
|
|
|
|
Vector3 _endDir = target; |
|
|
|
|
|
|
|
|
int RotationDir = 0; |
|
|
|
|
|
switch (direction) |
|
|
|
|
|
{ |
|
|
|
|
|
case Direction.Forward: |
|
|
|
|
|
RotationDir = 0; |
|
|
|
|
|
break; |
|
|
|
|
|
case Direction.Left: |
|
|
|
|
|
RotationDir = -1; |
|
|
|
|
|
break; |
|
|
|
|
|
case Direction.Right: |
|
|
|
|
|
RotationDir = 1; |
|
|
|
|
|
break; |
|
|
|
|
|
case Direction.Back: |
|
|
|
|
|
RotationDir = 2; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 _startPos = transform.position; |
|
|
|
|
|
|
|
|
|
|
|
float elapsedTime = 0; |
|
|
float elapsedTime = 0; |
|
|
while (elapsedTime / time < 1) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
float anglePerSecond = (angles * RotationDir) / time; |
|
|
|
|
|
Vector3 _startPos = transform.position; |
|
|
|
|
|
Vector3 startDirection = transform.forward; |
|
|
|
|
|
|
|
|
transform.forward = Vector3.Slerp(_startDir, _endDir, (elapsedTime / time)); |
|
|
|
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
transform.Rotate(Vector3.up, anglePerSecond * Time.deltaTime); |
|
|
|
|
|
|
|
|
if (heightOffset != null) |
|
|
if (heightOffset != null) |
|
|
transform.position = _startPos + Vector3.up * heightOffset(elapsedTime / time); |
|
|
|
|
|
|
|
|
transform.position = _startPos + Vector3.up * heightOffset(elapsedTime / time); |
|
|
|
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
elapsedTime += Time.deltaTime; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
transform.forward = target; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transform.forward = Quaternion.AngleAxis(angles * RotationDir, Vector3.up) * startDirection; |
|
|
if (heightOffset != null) |
|
|
if (heightOffset != null) |
|
|
transform.position = _startPos + Vector3.up * heightOffset(1); |
|
|
transform.position = _startPos + Vector3.up * heightOffset(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerator AnimateToPosition(Vector3 position, Animation animation, float time) |
|
|
public IEnumerator AnimateToPosition(Vector3 position, Animation animation, float time) |
|
|
{ |
|
|
{ |
|
|
System.Func<float, float> yFunction = null; |
|
|
System.Func<float, float> yFunction = null; |
|
|