|
|
@ -52,7 +52,7 @@ public class Character : MonoBehaviour |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IEnumerator MoveCoroutine(Block Target, Transform Current, float time) |
|
|
|
IEnumerator MoveCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
|
{ |
|
|
|
float elapsedTime = 0; |
|
|
|
Vector3 startPosition = Current.position; |
|
|
@ -60,14 +60,14 @@ public class Character : MonoBehaviour |
|
|
|
while (elapsedTime < time) |
|
|
|
{ |
|
|
|
transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time)); |
|
|
|
transform.position += yValue((elapsedTime / time), 0.3f); |
|
|
|
transform.position += yValue((elapsedTime / time), heightMax); |
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
} |
|
|
|
transform.position = Target.VisualPosition; |
|
|
|
} |
|
|
|
|
|
|
|
IEnumerator rotateCoroutine(Direction direction, Transform Current, float time) |
|
|
|
IEnumerator rotateCoroutine(Direction direction, Transform Current, float time, float heightMax) |
|
|
|
{ |
|
|
|
float elapsedTime = 0; |
|
|
|
time *= 0.8f; |
|
|
@ -77,7 +77,7 @@ public class Character : MonoBehaviour |
|
|
|
while (elapsedTime < time) |
|
|
|
{ |
|
|
|
transform.forward = Vector3.Slerp(startDirection, endDirection, (elapsedTime / time)); |
|
|
|
transform.position = startPosition +yValue((elapsedTime / time), 0.15f); |
|
|
|
transform.position = startPosition +yValue((elapsedTime / time), heightMax); |
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
} |
|
|
@ -111,7 +111,7 @@ public class Character : MonoBehaviour |
|
|
|
|
|
|
|
//set current block && move
|
|
|
|
CurrentBlock = moveTo; |
|
|
|
StartCoroutine(MoveCoroutine(CurrentBlock, transform, speed)); |
|
|
|
StartCoroutine(MoveCoroutine(CurrentBlock, transform, speed, 0.3f)); |
|
|
|
//transform.position = CurrentBlock.VisualPosition;
|
|
|
|
} |
|
|
|
|
|
|
@ -141,7 +141,7 @@ public class Character : MonoBehaviour |
|
|
|
/// <param name="direction">Local direction to point</param>
|
|
|
|
public void Rotate(Direction direction, float speed) |
|
|
|
{ |
|
|
|
StartCoroutine(rotateCoroutine(direction, transform, speed)); |
|
|
|
StartCoroutine(rotateCoroutine(direction, transform, speed, 0.15f)); |
|
|
|
//transform.forward = direction.ToVector(transform);
|
|
|
|
} |
|
|
|
|
|
|
@ -149,13 +149,13 @@ public class Character : MonoBehaviour |
|
|
|
/// Jumps in specefied direction, picks between Long Jump and Jumping up
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="direction">Direction to Jump</param>
|
|
|
|
public void Jump(Direction direction) |
|
|
|
public void Jump(Direction direction, float speed) |
|
|
|
{ |
|
|
|
//if there is a block infront JumpUp else LongJump
|
|
|
|
if (Block.isBlockAtPosition(CurrentBlock.position + direction.ToVector(transform) + Vector3.up, 1, ~Ignore)) |
|
|
|
JumpUp(direction); |
|
|
|
JumpUp(direction, speed); |
|
|
|
else |
|
|
|
JumpLong(direction); |
|
|
|
JumpLong(direction, speed); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion Class Implementation
|
|
|
@ -167,7 +167,7 @@ public class Character : MonoBehaviour |
|
|
|
/// </summary>
|
|
|
|
/// <param name="direction">Direction of obstacle</param>
|
|
|
|
/// <param name="height">max height</param>
|
|
|
|
private void JumpUp(Direction direction, int height = 1) |
|
|
|
private void JumpUp(Direction direction, float speed, int height = 1) |
|
|
|
{ |
|
|
|
//setting up variables
|
|
|
|
Vector3 position; // position wanted
|
|
|
@ -187,7 +187,8 @@ public class Character : MonoBehaviour |
|
|
|
|
|
|
|
//set current block && move
|
|
|
|
CurrentBlock = moveTo; |
|
|
|
transform.position = CurrentBlock.VisualPosition; |
|
|
|
StartCoroutine(MoveCoroutine(CurrentBlock, transform, speed, 0.5f)); |
|
|
|
//transform.position = CurrentBlock.VisualPosition;
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -195,7 +196,7 @@ public class Character : MonoBehaviour |
|
|
|
/// </summary>
|
|
|
|
/// <param name="direction">Direction to Jump</param>
|
|
|
|
/// <param name="Distance">Max distance</param>
|
|
|
|
private void JumpLong(Direction direction, int Distance = 2) |
|
|
|
private void JumpLong(Direction direction, float speed, int Distance = 2) |
|
|
|
{ |
|
|
|
//setting up variables
|
|
|
|
Vector3 position; // position wanted
|
|
|
@ -224,7 +225,8 @@ public class Character : MonoBehaviour |
|
|
|
|
|
|
|
//Set Current Block and move
|
|
|
|
CurrentBlock = moveTo; |
|
|
|
transform.position = CurrentBlock.VisualPosition; |
|
|
|
StartCoroutine(MoveCoroutine(CurrentBlock, transform, speed, 0.5f)); |
|
|
|
//transform.position = CurrentBlock.VisualPosition;
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion Private Functions
|
|
|
|