Commit e4bd7224 by Philipp Adolf

Store dash direction as Vector2

parent d18a8444
......@@ -14,9 +14,9 @@ public class PlayerControl : MonoBehaviour
public float targetJumpHeight = 2f;
public float lastDashStart = float.NegativeInfinity;
[HideInInspector]
public float currentDashDirection = 0.0f;
public Vector2 dashDirection = Vector2.right;
[HideInInspector]
public float dashDirection = 1.0f;
public Vector2 currentDashDirection = Vector2.right;
public float dashCompletionTime = 0.25f;
public float dashStartSpeed = 20.0f;
public float dashEndSpeed = 8.0f;
......@@ -93,14 +93,7 @@ public class PlayerControl : MonoBehaviour
if (_controller.isGrounded)
velocity.y = 0;
if (Input.GetKey (goRightKeyCode))
{
dashDirection = 1.0f;
}
else if (Input.GetKey (goLeftKeyCode))
{
dashDirection = -1.0f;
}
updateDashDirection();
if (canDash () && Input.GetKey (dashKeyCode))
{
......@@ -111,8 +104,7 @@ public class PlayerControl : MonoBehaviour
if (isDashing ())
{
velocity.x = Mathf.Lerp(currentDashDirection * dashStartSpeed, currentDashDirection * dashEndSpeed, getDashTime() / dashCompletionTime);
velocity.y = 0;
velocity = currentDashDirection * Mathf.Lerp(dashStartSpeed, dashEndSpeed, getDashTime() / dashCompletionTime);
}
else
{
......@@ -171,6 +163,24 @@ public class PlayerControl : MonoBehaviour
_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 ()
{
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