Commit b98dc720 by Philipp Adolf

Make player dash with 'down' key

parent d9140ec0
...@@ -11,6 +11,8 @@ public class PlayerControl : MonoBehaviour ...@@ -11,6 +11,8 @@ public class PlayerControl : MonoBehaviour
public float groundDamping = 20f; // how fast do we change direction? higher means faster public float groundDamping = 20f; // how fast do we change direction? higher means faster
public float inAirDamping = 5f; public float inAirDamping = 5f;
public float targetJumpHeight = 2f; public float targetJumpHeight = 2f;
public bool canDash = true;
public float dashCoolDown = 0.25f;
// public float jumpWaitTime = 2.0; // public float jumpWaitTime = 2.0;
[HideInInspector] [HideInInspector]
...@@ -25,7 +27,7 @@ public class PlayerControl : MonoBehaviour ...@@ -25,7 +27,7 @@ public class PlayerControl : MonoBehaviour
public Vector3 velocity; public Vector3 velocity;
public int playerNumber = 1; //gibt an, ob es sich um player one, player two, etc. handelt. sollte nicht 0 sein; public int playerNumber = 1; //gibt an, ob es sich um player one, player two, etc. handelt. sollte nicht 0 sein;
KeyCode goRightKeyCode, goLeftKeyCode, jumpKeyCode; KeyCode goRightKeyCode, goLeftKeyCode, jumpKeyCode, dashKeyCode;
void Start() void Start()
{ {
...@@ -35,10 +37,10 @@ public class PlayerControl : MonoBehaviour ...@@ -35,10 +37,10 @@ public class PlayerControl : MonoBehaviour
switch (playerNumber) switch (playerNumber)
{ {
case 1: case 1:
setKeyCodes(KeyCode.D,KeyCode.A,KeyCode.W); setKeyCodes(KeyCode.D, KeyCode.A, KeyCode.W, KeyCode.S);
break; break;
case 2: case 2:
setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow); setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow, KeyCode.DownArrow);
break; break;
//TODO player 3 and 4 //TODO player 3 and 4
default: default:
...@@ -46,11 +48,12 @@ public class PlayerControl : MonoBehaviour ...@@ -46,11 +48,12 @@ public class PlayerControl : MonoBehaviour
} }
} }
private void setKeyCodes(KeyCode right, KeyCode left, KeyCode up) private void setKeyCodes(KeyCode right, KeyCode left, KeyCode up, KeyCode dash)
{ {
goRightKeyCode = right; goRightKeyCode = right;
goLeftKeyCode = left; goLeftKeyCode = left;
jumpKeyCode = up; jumpKeyCode = up;
dashKeyCode = dash;
} }
...@@ -97,6 +100,19 @@ public class PlayerControl : MonoBehaviour ...@@ -97,6 +100,19 @@ public class PlayerControl : MonoBehaviour
//if (_controller.isGrounded) //if (_controller.isGrounded)
} }
if (canDash && Input.GetKey (dashKeyCode))
{
float direction = Mathf.Sign (transform.localScale.x);
if (normalizedHorizontalSpeed != 0)
{
// player pressed a movement button so prefer the new direction
direction = Mathf.Sign (normalizedHorizontalSpeed);
}
normalizedHorizontalSpeed = 5 * direction;
canDash = false;
Invoke("EnableDash", dashCoolDown);
}
if (Input.GetKeyDown(jumpKeyCode)) if (Input.GetKeyDown(jumpKeyCode))
{ {
...@@ -119,4 +135,8 @@ public class PlayerControl : MonoBehaviour ...@@ -119,4 +135,8 @@ public class PlayerControl : MonoBehaviour
} }
} void EnableDash()
\ No newline at end of file {
canDash = true;
}
}
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