Commit e4bd7224 by Philipp Adolf

Store dash direction as Vector2

parent d18a8444
...@@ -14,9 +14,9 @@ public class PlayerControl : MonoBehaviour ...@@ -14,9 +14,9 @@ public class PlayerControl : MonoBehaviour
public float targetJumpHeight = 2f; public float targetJumpHeight = 2f;
public float lastDashStart = float.NegativeInfinity; public float lastDashStart = float.NegativeInfinity;
[HideInInspector] [HideInInspector]
public float currentDashDirection = 0.0f; public Vector2 dashDirection = Vector2.right;
[HideInInspector] [HideInInspector]
public float dashDirection = 1.0f; public Vector2 currentDashDirection = Vector2.right;
public float dashCompletionTime = 0.25f; public float dashCompletionTime = 0.25f;
public float dashStartSpeed = 20.0f; public float dashStartSpeed = 20.0f;
public float dashEndSpeed = 8.0f; public float dashEndSpeed = 8.0f;
...@@ -93,14 +93,7 @@ public class PlayerControl : MonoBehaviour ...@@ -93,14 +93,7 @@ public class PlayerControl : MonoBehaviour
if (_controller.isGrounded) if (_controller.isGrounded)
velocity.y = 0; velocity.y = 0;
if (Input.GetKey (goRightKeyCode)) updateDashDirection();
{
dashDirection = 1.0f;
}
else if (Input.GetKey (goLeftKeyCode))
{
dashDirection = -1.0f;
}
if (canDash () && Input.GetKey (dashKeyCode)) if (canDash () && Input.GetKey (dashKeyCode))
{ {
...@@ -111,8 +104,7 @@ public class PlayerControl : MonoBehaviour ...@@ -111,8 +104,7 @@ public class PlayerControl : MonoBehaviour
if (isDashing ()) if (isDashing ())
{ {
velocity.x = Mathf.Lerp(currentDashDirection * dashStartSpeed, currentDashDirection * dashEndSpeed, getDashTime() / dashCompletionTime); velocity = currentDashDirection * Mathf.Lerp(dashStartSpeed, dashEndSpeed, getDashTime() / dashCompletionTime);
velocity.y = 0;
} }
else else
{ {
...@@ -171,6 +163,24 @@ public class PlayerControl : MonoBehaviour ...@@ -171,6 +163,24 @@ public class PlayerControl : MonoBehaviour
_controller.move(velocity * Time.deltaTime); _controller.move(velocity * Time.deltaTime);
} }
private void updateDashDirection()
{
float horizontalDashDirection = 0.0f;
if (Input.GetKey (goRightKeyCode))
{
horizontalDashDirection = 1.0f;
}
else if (Input.GetKey (goLeftKeyCode))
{
horizontalDashDirection = -1.0f;
}
float verticalDashDirection = 0.0f;
if (horizontalDashDirection != 0.0f || verticalDashDirection != 0.0f)
dashDirection = new Vector2(horizontalDashDirection, verticalDashDirection);
}
private float getDashTime () private float getDashTime ()
{ {
return Time.time - lastDashStart; return Time.time - lastDashStart;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment