|
@ -151,83 +151,7 @@ public class Character : MonoBehaviour |
|
|
StopAnimation(animation); |
|
|
StopAnimation(animation); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private IEnumerator LerpToBlock(Vector3 target, float time, System.Func<float, float> heightOffset = null) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
Vector3 _startPos = transform.position; |
|
|
|
|
|
Vector3 _endPos = target; |
|
|
|
|
|
|
|
|
|
|
|
Vector3 _newPos; |
|
|
|
|
|
|
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (elapsedTime / time < 1) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
_newPos = Vector3.Lerp(_startPos, _endPos, (elapsedTime / time)); |
|
|
|
|
|
|
|
|
|
|
|
if (heightOffset != null) |
|
|
|
|
|
_newPos.y += heightOffset(elapsedTime / time); |
|
|
|
|
|
|
|
|
|
|
|
transform.position = _newPos; |
|
|
|
|
|
|
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
|
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_newPos = _endPos; |
|
|
|
|
|
if (heightOffset != null) |
|
|
|
|
|
_newPos.y += heightOffset(1); |
|
|
|
|
|
|
|
|
|
|
|
transform.position = _newPos; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator Rotate(Direction direction, float angles, float time, System.Func<float, float> heightOffset = null) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lastRotation = angles * RotationDir; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
float anglePerSecond = (angles * RotationDir) / time; |
|
|
|
|
|
Vector3 _startPos = transform.position; |
|
|
|
|
|
Vector3 startDirection = transform.forward; |
|
|
|
|
|
|
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
transform.Rotate(Vector3.up, anglePerSecond * Time.deltaTime); |
|
|
|
|
|
|
|
|
|
|
|
if (heightOffset != null) |
|
|
|
|
|
transform.position = _startPos + Vector3.up * heightOffset(elapsedTime / time); |
|
|
|
|
|
|
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
transform.forward = Quaternion.AngleAxis(angles * RotationDir, Vector3.up) * startDirection; |
|
|
|
|
|
if (heightOffset != null) |
|
|
|
|
|
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) |
|
@ -289,8 +213,12 @@ public class Character : MonoBehaviour |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void respawnCharacter() |
|
|
public void respawnCharacter() |
|
|
|
|
|
{ |
|
|
|
|
|
respawnCharacter(CurrentBlock.position); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void respawnCharacter(Vector3 respawnPosition) |
|
|
{ |
|
|
{ |
|
|
/* Will introduce more complex criteria for choosing where to respawn the player in future |
|
|
/* Will introduce more complex criteria for choosing where to respawn the player in future |
|
|
* For now: if the square one back (x =- 1) from the pit is walkable and unoccupied, then put them there |
|
|
* For now: if the square one back (x =- 1) from the pit is walkable and unoccupied, then put them there |
|
@ -299,7 +227,7 @@ public class Character : MonoBehaviour |
|
|
|
|
|
|
|
|
Block currentBlock = null; |
|
|
Block currentBlock = null; |
|
|
//We start from the position of our pit, at ground level
|
|
|
//We start from the position of our pit, at ground level
|
|
|
Vector3 currentPos = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z); |
|
|
|
|
|
|
|
|
Vector3 currentPos = respawnPosition; |
|
|
|
|
|
|
|
|
Debug.Log("Commencing respawn"); |
|
|
Debug.Log("Commencing respawn"); |
|
|
|
|
|
|
|
@ -395,386 +323,93 @@ public class Character : MonoBehaviour |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Rotates to point in specific direction based on current direction
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="direction">Local direction to point</param>
|
|
|
|
|
|
public void Rotate(Direction direction, float speed) |
|
|
|
|
|
{ |
|
|
|
|
|
StartCoroutine(rotateCoroutine(direction, transform, speed, 0.15f)); |
|
|
|
|
|
//transform.forward = direction.ToVector(transform);
|
|
|
|
|
|
} |
|
|
|
|
|
public void RotateHalf(Direction direction, float speed) |
|
|
|
|
|
{ |
|
|
|
|
|
StartCoroutine(rotateHalfCoroutine(direction, transform, speed, 0.15f)); |
|
|
|
|
|
//transform.forward = direction.ToVector(transform);
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Jumps in specefied direction, picks between Long Jump and Jumping up
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="direction">Direction to Jump</param>
|
|
|
|
|
|
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, speed); |
|
|
|
|
|
else |
|
|
|
|
|
JumpLong(direction, speed); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion Class Implementation
|
|
|
#endregion Class Implementation
|
|
|
|
|
|
|
|
|
#region Private Functions
|
|
|
#region Private Functions
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Jumps up obstacle of specific height. Jumps as high as possible
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="direction">Direction of obstacle</param>
|
|
|
|
|
|
/// <param name="height">max height</param>
|
|
|
|
|
|
private void JumpUp(Direction direction, float speed, int height = 1) |
|
|
|
|
|
|
|
|
private IEnumerator LerpToBlock(Vector3 target, float time, System.Func<float, float> heightOffset = null) |
|
|
{ |
|
|
{ |
|
|
//setting up variables
|
|
|
|
|
|
Vector3 position; // position wanted
|
|
|
|
|
|
Block hit; //output of block detection
|
|
|
|
|
|
Block moveTo = _currentBlock; //block we'll actually move to
|
|
|
|
|
|
|
|
|
|
|
|
//Check blocks in going up then move to the heighest walkable one
|
|
|
|
|
|
for (int i = 0; i <= height; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
//next position up the tower
|
|
|
|
|
|
position = _currentBlock.position + direction.ToVector(transform) + (Vector3.up * i); |
|
|
|
|
|
|
|
|
|
|
|
//if block is walkable set it to last known position
|
|
|
|
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//set current block && move
|
|
|
|
|
|
_currentBlock = moveTo; |
|
|
|
|
|
StartCoroutine(JumpCoroutine(_currentBlock, transform, speed, 0.5f)); |
|
|
|
|
|
//transform.position = CurrentBlock.VisualPosition;
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Vector3 _startPos = transform.position; |
|
|
|
|
|
Vector3 _endPos = target; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Long jumps forward a specified distance. Can Jump gaps. Stops at obstruction
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="direction">Direction to Jump</param>
|
|
|
|
|
|
/// <param name="Distance">Max distance</param>
|
|
|
|
|
|
private void JumpLong(Direction direction, float speed, int Distance = 2) |
|
|
|
|
|
{ |
|
|
|
|
|
//setting up variables
|
|
|
|
|
|
Vector3 position; // position wanted
|
|
|
|
|
|
Block hit; //output of block detection
|
|
|
|
|
|
Block moveTo = _currentBlock; //block we'll actually move to
|
|
|
|
|
|
|
|
|
Vector3 _newPos; |
|
|
|
|
|
|
|
|
//Check blocks in front until we hit an obstruction or went the distance
|
|
|
|
|
|
for (int i = 1; i <= Distance; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
//Next position to MoveTo
|
|
|
|
|
|
position = _currentBlock.position + (direction.ToVector(transform) * i); |
|
|
|
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
|
|
|
//if jump is obstructed, stop and go to last known block
|
|
|
|
|
|
if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore)) |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//If block at Position is walkable set it to last known position
|
|
|
|
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
//else if block down one is walkable
|
|
|
|
|
|
else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
|
|
|
while (elapsedTime / time < 1) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
}//end for
|
|
|
|
|
|
|
|
|
_newPos = Vector3.Lerp(_startPos, _endPos, (elapsedTime / time)); |
|
|
|
|
|
|
|
|
//Set Current Block and move
|
|
|
|
|
|
_currentBlock = moveTo; |
|
|
|
|
|
StartCoroutine(JumpCoroutine(_currentBlock, transform, speed, 0.5f)); |
|
|
|
|
|
//transform.position = CurrentBlock.VisualPosition;
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (heightOffset != null) |
|
|
|
|
|
_newPos.y += heightOffset(elapsedTime / time); |
|
|
|
|
|
|
|
|
#endregion Private Functions
|
|
|
|
|
|
|
|
|
transform.position = _newPos; |
|
|
|
|
|
|
|
|
#region Depricated
|
|
|
|
|
|
IEnumerator JumpCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
|
|
|
{ |
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
Vector3 startPosition = Current.position; |
|
|
|
|
|
time *= 0.8f; |
|
|
|
|
|
characterAnimator.Play("Jump Inplace"); |
|
|
|
|
|
yield return new WaitForSeconds(0.15f); |
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time)); |
|
|
|
|
|
//transform.position += yValue((elapsedTime / time), heightMax);
|
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
yield return new WaitForEndOfFrame(); |
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
transform.position = Target.VisualPosition; |
|
|
|
|
|
} |
|
|
|
|
|
IEnumerator MoveCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
|
|
|
{ |
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
Vector3 startPosition = Current.position; |
|
|
|
|
|
time *= 0.8f; |
|
|
|
|
|
characterAnimator.Play("Walk"); |
|
|
|
|
|
yield return new WaitForSeconds(0.05f); |
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time)); |
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
transform.position = Target.VisualPosition; |
|
|
|
|
|
} |
|
|
|
|
|
IEnumerator MoveConveyorForwardCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
|
|
|
{ |
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
Vector3 startPosition = Current.position; |
|
|
|
|
|
Vector3 charEndPosition = new Vector3(Current.position.x + 1.0f, Current.position.y, Current.position.z); |
|
|
|
|
|
time *= 0.8f; |
|
|
|
|
|
yield return new WaitForSeconds(0.05f); |
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time)); |
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
Current.position = charEndPosition; |
|
|
|
|
|
} |
|
|
|
|
|
IEnumerator MoveConveyorBackwardCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
|
|
|
{ |
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
Vector3 startPosition = Current.position; |
|
|
|
|
|
Vector3 charEndPosition = new Vector3(Current.position.x - 1.0f, Current.position.y, Current.position.z); |
|
|
|
|
|
time *= 0.8f; |
|
|
|
|
|
yield return new WaitForSeconds(0.05f); |
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time)); |
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
Current.position = charEndPosition; |
|
|
|
|
|
} |
|
|
|
|
|
IEnumerator MoveConveyorLeftCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
|
|
|
{ |
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
Vector3 startPosition = Current.position; |
|
|
|
|
|
Vector3 charEndPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z + 1.0f); |
|
|
|
|
|
time *= 0.8f; |
|
|
|
|
|
yield return new WaitForSeconds(0.05f); |
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time)); |
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
elapsedTime += Time.deltaTime; |
|
|
} |
|
|
} |
|
|
Current.position = charEndPosition; |
|
|
|
|
|
} |
|
|
|
|
|
IEnumerator MoveConveyorRightCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
|
|
|
{ |
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
Vector3 startPosition = Current.position; |
|
|
|
|
|
Vector3 charEndPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z - 1.0f); |
|
|
|
|
|
time *= 0.8f; |
|
|
|
|
|
yield return new WaitForSeconds(0.05f); |
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time)); |
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
Current.position = charEndPosition; |
|
|
|
|
|
} |
|
|
|
|
|
IEnumerator PushLeftCoroutine(Transform Current, float time) |
|
|
|
|
|
{ |
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
Vector3 startPosition = Current.transform.position; |
|
|
|
|
|
Vector3 endPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z + 1.0f); |
|
|
|
|
|
time *= 0.8f; |
|
|
|
|
|
yield return new WaitForSeconds(0.05f); |
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
Current.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time)); |
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
Current.position = endPosition; |
|
|
|
|
|
} |
|
|
|
|
|
IEnumerator PushRightCoroutine(Transform Current, float time) |
|
|
|
|
|
{ |
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
Vector3 startPosition = Current.transform.position; |
|
|
|
|
|
Vector3 endPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z - 1.0f); |
|
|
|
|
|
time *= 0.8f; |
|
|
|
|
|
yield return new WaitForSeconds(0.05f); |
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
Current.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time)); |
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
Current.position = endPosition; |
|
|
|
|
|
} |
|
|
|
|
|
IEnumerator MoveDownCoroutine(Block Target, Transform Current, float time, float heightMax) |
|
|
|
|
|
{ |
|
|
|
|
|
float elapsedTime = 0; |
|
|
|
|
|
Vector3 startPosition = Current.position; |
|
|
|
|
|
time *= 0.8f; |
|
|
|
|
|
characterAnimator.Play("Walk"); |
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
{ |
|
|
|
|
|
transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time)); |
|
|
|
|
|
//transform.position += yValue((elapsedTime / time), heightMax);
|
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
} |
|
|
|
|
|
transform.position = Target.VisualPosition; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_newPos = _endPos; |
|
|
|
|
|
if (heightOffset != null) |
|
|
|
|
|
_newPos.y += heightOffset(1); |
|
|
|
|
|
|
|
|
|
|
|
transform.position = _newPos; |
|
|
} |
|
|
} |
|
|
IEnumerator rotateCoroutine(Direction direction, Transform Current, float time, float heightMax) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator Rotate(Direction direction, float angles, float time, System.Func<float, float> heightOffset = null) |
|
|
{ |
|
|
{ |
|
|
float elapsedTime = 0; |
|
|
|
|
|
time *= 0.8f; |
|
|
|
|
|
Vector3 endDirection = direction.ToVector(Current); |
|
|
|
|
|
Vector3 startDirection = Current.forward; |
|
|
|
|
|
while (elapsedTime < time) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int RotationDir = 0; |
|
|
|
|
|
switch (direction) |
|
|
{ |
|
|
{ |
|
|
characterAnimator.Play("Jump"); |
|
|
|
|
|
transform.forward = Vector3.Slerp(startDirection, endDirection, (elapsedTime / time)); |
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
|
|
|
elapsedTime += Time.deltaTime; |
|
|
|
|
|
|
|
|
case Direction.Forward: |
|
|
|
|
|
RotationDir = 0; |
|
|
|
|
|
break; |
|
|
|
|
|
case Direction.Left: |
|
|
|
|
|
RotationDir = -1; |
|
|
|
|
|
break; |
|
|
|
|
|
case Direction.Right: |
|
|
|
|
|
RotationDir = 1; |
|
|
|
|
|
break; |
|
|
|
|
|
case Direction.Back: |
|
|
|
|
|
RotationDir = 2; |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
transform.forward = endDirection; |
|
|
|
|
|
} |
|
|
|
|
|
IEnumerator rotateHalfCoroutine(Direction direction, Transform Current, float time, float heightMax) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastRotation = angles * RotationDir; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float elapsedTime = 0; |
|
|
float elapsedTime = 0; |
|
|
time *= 0.8f; |
|
|
|
|
|
Vector3 endDirection = (direction.ToVector(Current) + Current.forward).normalized; |
|
|
|
|
|
Vector3 startDirection = Current.forward; |
|
|
|
|
|
|
|
|
float anglePerSecond = (angles * RotationDir) / time; |
|
|
|
|
|
Vector3 _startPos = transform.position; |
|
|
|
|
|
Vector3 startDirection = transform.forward; |
|
|
|
|
|
|
|
|
while (elapsedTime < time) |
|
|
while (elapsedTime < time) |
|
|
{ |
|
|
{ |
|
|
characterAnimator.Play("Jump"); |
|
|
|
|
|
transform.forward = Vector3.Slerp(startDirection, endDirection, (elapsedTime / time)); |
|
|
|
|
|
|
|
|
transform.Rotate(Vector3.up, anglePerSecond * Time.deltaTime); |
|
|
|
|
|
|
|
|
|
|
|
if (heightOffset != null) |
|
|
|
|
|
transform.position = _startPos + Vector3.up * heightOffset(elapsedTime / time); |
|
|
|
|
|
|
|
|
yield return new WaitForEndOfFrame(); |
|
|
yield return new WaitForEndOfFrame(); |
|
|
elapsedTime += Time.deltaTime; |
|
|
elapsedTime += Time.deltaTime; |
|
|
} |
|
|
} |
|
|
transform.forward = endDirection; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Moves one block in specefied direction, Can walk off obstacles
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="direction">direction to walk</param>
|
|
|
|
|
|
/// <remarks>Technically is same as JumpLong(1) but kept seperate to avoid confusion</remarks>
|
|
|
|
|
|
public void Move(Direction direction, float speed) |
|
|
|
|
|
{ |
|
|
|
|
|
//setting up variables
|
|
|
|
|
|
Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
|
|
|
|
|
|
Block hit; //output of block detection
|
|
|
|
|
|
Block moveTo = _currentBlock; //block we'll actually move to
|
|
|
|
|
|
|
|
|
|
|
|
//if move is obstucted no where to move
|
|
|
|
|
|
if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore)) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//If block at Position is walkable set it to moveTo
|
|
|
|
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
{ |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
_currentBlock = moveTo; |
|
|
|
|
|
StartCoroutine(MoveCoroutine(_currentBlock, transform, speed, 0.3f)); |
|
|
|
|
|
} |
|
|
|
|
|
//else if block down one is walkable
|
|
|
|
|
|
else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
{ |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
_currentBlock = moveTo; |
|
|
|
|
|
StartCoroutine(MoveDownCoroutine(_currentBlock, transform, speed, 0.3f)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
transform.forward = Quaternion.AngleAxis(angles * RotationDir, Vector3.up) * startDirection; |
|
|
|
|
|
if (heightOffset != null) |
|
|
|
|
|
transform.position = _startPos + Vector3.up * heightOffset(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void conveyorMoveForward(Direction direction, float speed) |
|
|
|
|
|
{ |
|
|
|
|
|
Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
|
|
|
|
|
|
Block hit; //output of block detection
|
|
|
|
|
|
Block moveTo = _currentBlock; //block we'll actually move to
|
|
|
|
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
{ |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
_currentBlock = moveTo; |
|
|
|
|
|
StartCoroutine(MoveConveyorForwardCoroutine(_currentBlock, transform, speed, 0.3f)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
public void conveyorMoveBackward(Direction direction, float speed) |
|
|
|
|
|
{ |
|
|
|
|
|
Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
|
|
|
|
|
|
Block hit; //output of block detection
|
|
|
|
|
|
Block moveTo = _currentBlock; //block we'll actually move to
|
|
|
|
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
{ |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
_currentBlock = moveTo; |
|
|
|
|
|
StartCoroutine(MoveConveyorBackwardCoroutine(_currentBlock, transform, speed, 0.3f)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
public void conveyorMoveLeft(Direction direction, float speed) |
|
|
|
|
|
{ |
|
|
|
|
|
Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
|
|
|
|
|
|
Block hit; //output of block detection
|
|
|
|
|
|
Block moveTo = _currentBlock; //block we'll actually move to
|
|
|
|
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
{ |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
_currentBlock = moveTo; |
|
|
|
|
|
StartCoroutine(MoveConveyorLeftCoroutine(_currentBlock, transform, speed, 0.3f)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
public void conveyorMoveRight(Direction direction, float speed) |
|
|
|
|
|
{ |
|
|
|
|
|
Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
|
|
|
|
|
|
Block hit; //output of block detection
|
|
|
|
|
|
Block moveTo = _currentBlock; //block we'll actually move to
|
|
|
|
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
{ |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
_currentBlock = moveTo; |
|
|
|
|
|
StartCoroutine(MoveConveyorRightCoroutine(_currentBlock, transform, speed, 0.3f)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void CannonRMove(float speed) |
|
|
|
|
|
{ |
|
|
|
|
|
Direction direction = Direction.Right; |
|
|
|
|
|
Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
|
|
|
|
|
|
Block hit; //output of block detection
|
|
|
|
|
|
Block moveTo = _currentBlock; //block we'll actually move to
|
|
|
|
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
{ |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
_currentBlock = moveTo; |
|
|
|
|
|
StartCoroutine(PushRightCoroutine(transform, speed)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
public void CannonLMove(float speed) |
|
|
|
|
|
{ |
|
|
|
|
|
Direction direction = Direction.Left; |
|
|
|
|
|
Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
|
|
|
|
|
|
Block hit; //output of block detection
|
|
|
|
|
|
Block moveTo = _currentBlock; //block we'll actually move to
|
|
|
|
|
|
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) |
|
|
|
|
|
{ |
|
|
|
|
|
moveTo = hit; |
|
|
|
|
|
_currentBlock = moveTo; |
|
|
|
|
|
StartCoroutine(PushLeftCoroutine(transform, speed)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#endregion Private Functions
|
|
|
|
|
|
|
|
|
#endregion Depricated
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |