Commit 388fe66c by Tim Reiter
parents a5074f8d b98dc720
......@@ -11,6 +11,8 @@ public class PlayerControl : MonoBehaviour
public float groundDamping = 20f; // how fast do we change direction? higher means faster
public float inAirDamping = 5f;
public float targetJumpHeight = 2f;
public bool canDash = true;
public float dashCoolDown = 0.25f;
// public float jumpWaitTime = 2.0;
[HideInInspector]
......@@ -25,7 +27,7 @@ public class PlayerControl : MonoBehaviour
public Vector3 velocity;
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()
{
......@@ -35,10 +37,10 @@ public class PlayerControl : MonoBehaviour
switch (playerNumber)
{
case 1:
setKeyCodes(KeyCode.D,KeyCode.A,KeyCode.W);
setKeyCodes(KeyCode.D, KeyCode.A, KeyCode.W, KeyCode.S);
break;
case 2:
setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow);
setKeyCodes(KeyCode.RightArrow, KeyCode.LeftArrow, KeyCode.UpArrow, KeyCode.DownArrow);
break;
//TODO player 3 and 4
default:
......@@ -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;
goLeftKeyCode = left;
jumpKeyCode = up;
dashKeyCode = dash;
}
......@@ -97,6 +100,19 @@ public class PlayerControl : MonoBehaviour
//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))
{
......@@ -119,4 +135,8 @@ public class PlayerControl : MonoBehaviour
}
void EnableDash()
{
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