Browse Source

Added jump coroutine and little bounce in long jump and hgh jump

Josh_Dev_branch
Claire Peta 5 years ago
parent
commit
64d6867465
4 changed files with 24 additions and 22 deletions
  1. +7
    -7
      Assets/Scenes/TuteLevelFive.unity
  2. +15
    -13
      Assets/Scripts/Character.cs
  3. +1
    -1
      Assets/Scripts/KeyboardInput.cs
  4. +1
    -1
      Assets/Scripts/Logic/Blocks/Jump.cs

+ 7
- 7
Assets/Scenes/TuteLevelFive.unity View File

@ -840,7 +840,7 @@ PrefabInstance:
- target: {fileID: 5195354182462625300, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354182462625300, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
propertyPath: m_IsActive propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
@ -990,12 +990,12 @@ PrefabInstance:
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0.00012783865
value: -0.000061035156
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
propertyPath: m_SizeDelta.y propertyPath: m_SizeDelta.y
value: 0
value: -101.69998
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
@ -1081,7 +1081,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &204689276 --- !u!114 &204689276
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -4086,7 +4086,7 @@ PrefabInstance:
- target: {fileID: 7103365430685043221, guid: 80a26ed87f729434abe07a722ef15e7c, - target: {fileID: 7103365430685043221, guid: 80a26ed87f729434abe07a722ef15e7c,
type: 3} type: 3}
propertyPath: m_IsActive propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7103365430685043225, guid: 80a26ed87f729434abe07a722ef15e7c, - target: {fileID: 7103365430685043225, guid: 80a26ed87f729434abe07a722ef15e7c,
type: 3} type: 3}
@ -5990,7 +5990,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!65 &1691679947 --- !u!65 &1691679947
BoxCollider: BoxCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -6348,7 +6348,7 @@ PrefabInstance:
- target: {fileID: 6379596649083080720, guid: 12c252cb33f8c9d41be9fc3a9adb9bb9, - target: {fileID: 6379596649083080720, guid: 12c252cb33f8c9d41be9fc3a9adb9bb9,
type: 3} type: 3}
propertyPath: m_IsActive propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6379596649083080716, guid: 12c252cb33f8c9d41be9fc3a9adb9bb9, - target: {fileID: 6379596649083080716, guid: 12c252cb33f8c9d41be9fc3a9adb9bb9,
type: 3} type: 3}

+ 15
- 13
Assets/Scripts/Character.cs View File

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

+ 1
- 1
Assets/Scripts/KeyboardInput.cs View File

@ -37,7 +37,7 @@ public class KeyboardInput : MonoBehaviour
} }
if (Input.GetKeyDown(KeyCode.Space)) if (Input.GetKeyDown(KeyCode.Space))
{ {
character.Jump(Direction.Forward);
character.Jump(Direction.Forward, characterSpeed);
} }
} }

+ 1
- 1
Assets/Scripts/Logic/Blocks/Jump.cs View File

@ -21,7 +21,7 @@ public class Jump : LogicBlock
/// <param name="player">Player to move</param> /// <param name="player">Player to move</param>
protected override void BlockLogic(Character player, float animationTime) protected override void BlockLogic(Character player, float animationTime)
{ {
player.Jump(direction);
player.Jump(direction, animationTime);
} }
#endregion Class Functions #endregion Class Functions

Loading…
Cancel
Save