private void Dash() { if (_direction == DashDirection.None && _cooldownTimer <= 0) { if (Input.GetKeyDown(KeyCode.Q)) { _direction = DashDirection.Left; } else if (Input.GetKeyDown(KeyCode.E)) { _direction = DashDirection.Right; } } else { if (_dashTime <= 0) { ResetProperties(); } else { _dashTime -= Time.deltaTime; ChangeVelocity(); _animator.SetFloat("DashTime", _dashTime); } } }
/*private void ResetDash() * { * stockedDashes = totalDashes; * }*/ private void StopDash() { playerState.SetDashing(false); dashTimer = 0.0f; direction = DashDirection.None; ResetGravityDefault(); }
void FixedUpdate() { //Movement controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump, attacking, dashing); attacking = false; dashing = false; if (dashDirection != DashDirection.NoDirection) { if (dashTimer >= dashDuration) { dashDirection = DashDirection.NoDirection; dashTimer = 0; body.velocity = body.velocity; } else { dashTimer += Time.deltaTime; if (dashDirection == DashDirection.Left) { body.velocity = Vector2.left * dashSpeed; } if (dashDirection == DashDirection.Right) { body.velocity = Vector2.right * dashSpeed; } } } if (dashTimer == 0 && controller.GetM_Grounded()) { canDash = true; } jump = false; }
private void OnCollisionEnter2D(Collision2D collision) { if (isCharging) { AudioManager.instance.PlaySound("Jebsee_ChargeImpact"); /*if (collision.gameObject.GetComponent<BreakableWalls>()) * { * //Keep going * } * else * { * dashDirection = DashDirection.NoDirection; * dashTimer = 0; * body.velocity = Vector2.zero; * AudioManager.instance.StopSound("Jebsee_ChargeLoop"); * isCharging = false; * }*/ dashDirection = DashDirection.NoDirection; dashTimer = 0; body.velocity = Vector2.zero; AudioManager.instance.StopSound("Jebsee_ChargeLoop"); isCharging = false; } }
// Update is called once per frame void Update() { if (jebseeController.isActive && !isCharging) { if (Input.GetKey(jebseeController.left)) { dashDirection = DashDirection.Left; } if (Input.GetKey(jebseeController.right)) { dashDirection = DashDirection.Right; } if (dashDirection != DashDirection.NoDirection) { if (dashTimer >= dashDuration) { dashDirection = DashDirection.NoDirection; dashTimer = 0; body.velocity = Vector2.zero; AudioManager.instance.StopSound("Jebsee_ChargeLoop"); isCharging = false; } else { if (Input.GetKeyDown(KeyCode.Space) && jebseeController.isWalking) { isCharging = true; AudioManager.instance.PlaySound("Jebsee_ChargeLoop"); } if (isCharging) { dashTimer += Time.deltaTime; if (dashDirection == DashDirection.Left) { body.velocity = Vector2.left * dashSpeed; } if (dashDirection == DashDirection.Right) { body.velocity = Vector2.right * dashSpeed; } if (jebseeController.isWalking) { AudioManager.instance.StopSound("Jebsee_WalkCycle"); } } } } } }
void DashFunc() { //body.velocity = Vector3.zero; if ((Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) && Input.GetKeyDown(KeyCode.LeftShift)) { dashDirection = DashDirection.Down; } if ((Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) && Input.GetKeyDown(KeyCode.LeftShift)) { dashDirection = DashDirection.Up; } if ((Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) && Input.GetKeyDown(KeyCode.LeftShift)) { dashDirection = DashDirection.Left; } if ((Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) && Input.GetKeyDown(KeyCode.LeftShift)) { dashDirection = DashDirection.Right; } if (dashDirection != DashDirection.NoDirection) { if (dashTimer >= dashDuration) { dashDirection = DashDirection.NoDirection; dashTimer = 0; body.velocity = Vector3.zero; } else { dashTimer += Time.deltaTime; if (dashDirection == DashDirection.Left) { body.velocity = Vector3.left * dashSpeed; } if (dashDirection == DashDirection.Right) { body.velocity = Vector3.right * dashSpeed; } if (dashDirection == DashDirection.Up) { body.velocity = Vector3.forward * dashSpeed; } if (dashDirection == DashDirection.Down) { body.velocity = -Vector3.forward * dashSpeed; } } } }
void Update() { // body.velocity = Vector2.zero; //if (Input.GetKey(KeyCode.DownArrow)) //{ // dashDirection = DashDirection.Down; //} //if (Input.GetKey(KeyCode.UpArrow)) //{ // dashDirection = DashDirection.Up; //} //if (Input.GetKey(KeyCode.LeftArrow)) //{ // dashDirection = DashDirection.Left; //} if (Input.GetKeyDown(KeyCode.P)) { dashDirection = DashDirection.Right; } if (dashDirection != DashDirection.NoDirection) { if (dashTimer >= dashDuration) { dashDirection = DashDirection.NoDirection; dashTimer = 0; body.velocity = Vector2.zero; } else { dashTimer += Time.deltaTime; //if (dashDirection == DashDirection.Left) //{ // body.velocity = Vector2.left * dashSpeed; //} if (dashDirection == DashDirection.Right) { body.velocity = Vector2.right * dashSpeed; } //if (dashDirection == DashDirection.Up) //{ // body.velocity = Vector2.up * dashSpeed; //} //if (dashDirection == DashDirection.Down) //{ // body.velocity = Vector2.down * dashSpeed; //} } } }
public IEnumerator Dash(DashDirection dashDirection) { _dashing = true; dashCountdown = dashCooldown; var moveVector = new Vector3(); while (_dashTimer <= dashDuration) { if (dashDirection == DashDirection.Forward) { var playerTransform = transform; moveVector = playerTransform.right * 0 + playerTransform.forward * dashSpeed; } if (dashDirection == DashDirection.Left) { var playerTransform = transform; moveVector = playerTransform.right * 0 + -playerTransform.right * dashSpeed; } if (dashDirection == DashDirection.Right) { var playerTransform = transform; moveVector = playerTransform.right * 0 + playerTransform.right * dashSpeed; } if (dashDirection == DashDirection.Backwards) { var playerTransform = transform; moveVector = playerTransform.right * 0 + -playerTransform.forward * dashSpeed; } MoveController(moveVector); yield return(null); } _dashTimer = 0; _dashing = false; }
public void StartDash(DashDirection dir) { if (dashReady) { GameObject newDashEffect = null; if (dir == DashDirection.left) { newDashEffect = (GameObject)Instantiate(dashEffect, leftDashEffect.transform.position, Quaternion.Euler(0, 90, 0)); } else if (dir == DashDirection.right) { newDashEffect = (GameObject)Instantiate(dashEffect, rightDashEffect.transform.position, Quaternion.Euler(0, -90, 0)); } Destroy(newDashEffect, 1f); GetComponent <Rigidbody>().AddForce(new Vector3(dashForce, 0, 0) * (int)dir, ForceMode.Impulse); dashing = true; dashDirection = (int)dir; dashReady = false; dashTimer.Go(dashTime); nextDashTimer.Go(dashDelay); } }
public void CheckDash(DashDirection direction) { if (!_controller.collisions.below && _playerItems.HasAirDashEquipped && !_dashLeft && !_dashRight && !_gliding) { var facing = transform.localScale.x < 0 ? -1 : 1; if (direction == DashDirection.Right) { _dashRight = true; if (facing == -1) { Flip(); } } else if (direction == DashDirection.Left) { _dashLeft = true; if (facing == 1) { Flip(); } } } }
void Start() { body = GetComponent <Rigidbody>(); dashDirection = DashDirection.NoDirection; }
void FixedUpdate() { //dimension.executeShift(dashTime); if (playerState.IsGrounded() && dashTimer <= 0.0f) { ResetAirDash(); } /*if (dashBuffer > 0.0f) * { * dashBuffer -= Time.deltaTime; * * if (dashBuffer <= 0.0f) * { * dashBuffer = 0.0f; * ResetDash(); * } * }*/ if (inputEnabled && ((leftButtonPressed && rightButtonPressed) || (!leftButtonPressed && !rightButtonPressed))) { StayStationary(); } else if (leftButtonPressed) { MoveLeft(); } else if (rightButtonPressed) { MoveRight(); } if (dashButtonDown && !playerState.IsDashing() && (playerState.IsGrounded() || (!playerState.IsGrounded() && airDashes > 0))) { Debug.Log("wtf"); DisableJump(); if (!playerState.IsGrounded()) { airDashes--; } dashTimer = dashTime; //stockedDashes--; playerState.SetDashing(true); //Debug.Log("Is it dashing: "+playerState.IsDashing()); if (!IsFacingLeft()) { direction = DashDirection.Right; } else { direction = DashDirection.Left; } } if (playerState.IsDashing()) { if (direction == DashDirection.Left) { DashLeft(); } else if (direction == DashDirection.Right) { DashRight(); } dashTimer -= Time.deltaTime; if (dashTimer <= 0.0f) { StopDash(); EnableJump(); //dashBuffer = dashBufferTime; } else { //dimension.executeShift(dashTime); } } //dimension.dashShift(); }
void Update() { //Jumping if (isJumpKeyDown && !isDoubleJumpUsed && !isGrounded) { Jump(); isDoubleJumpUsed = true; } if (isJumpKeyDown && isGrounded) { Jump(); isGrounded = false; } moveVelocity -= moveVelocity + 0.01f; //Left Right Movement if (leftKeyDown) { moveVelocity = -speed; } if (rightKeyDown) { moveVelocity = speed; } if (lastInputDirection == DashDirection.Right && rightKeyUp) { Dash(true); } if (lastInputDirection == DashDirection.Left && leftKeyUp) { Dash(false); } if (doubleClickTimer > 0) { doubleClickTimer -= 1; } else { lastInputDirection = DashDirection.None; } //Dashing if (leftKeyUp) { doubleClickTimer = 100; if (doubleClickTimer > 0) { lastInputDirection = DashDirection.Left; } } if (rightKeyUp) { doubleClickTimer = 100; if (doubleClickTimer > 0) { lastInputDirection = DashDirection.Right; } } Move(); }
public DashCommand(DashDirection direction) { _direction = direction; }
void FixedUpdate() { if (playerState.IsGrounded() && dashTimer <= 0.0f) { ResetAirDash(); } if (dashBuffer > 0.0f) { dashBuffer -= Time.deltaTime; if (dashBuffer <= 0.0f) { dashBuffer = 0.0f; ResetDash(); } } if ((leftButtonPressed && rightButtonPressed) || (!leftButtonPressed && !rightButtonPressed)) { StayStationary(); } else if (leftButtonPressed) { MoveLeft(); } else if (rightButtonPressed) { MoveRight(); } if (dashButtonDown && !playerState.IsDashing() && stockedDashes > 0 && (playerState.IsGrounded() || (!playerState.IsGrounded() && airDashes > 0))) { DisableJump(); if (!playerState.IsGrounded()) { airDashes--; } dashTimer = dashTime; stockedDashes--; playerState.SetDashing(true); if (!IsFacingLeft()) { direction = DashDirection.Right; } else { direction = DashDirection.Left; } } if (playerState.IsDashing()) { if (direction == DashDirection.Left) { DashLeft(); } else if (direction == DashDirection.Right) { DashRight(); } dashTimer -= Time.deltaTime; if (dashTimer <= 0.0f) { StopDash(); EnableJump(); dashBuffer = dashBufferTime; } } }
private void ResetProperties() { _direction = DashDirection.None; _dashTime = _startDashTime; _rigidbody2D.velocity = Vector2.zero; }
// Update is called once per frame void Update() { horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed; animator.SetFloat("speed", Mathf.Abs(horizontalMove)); body.velocity = body.velocity; // body.velocity = Vector2.zero; if (Input.GetButtonDown("Jump")) { if (Input.GetKey("s")) { PlatformEffector2D effector = platform.GetComponent <PlatformEffector2D>(); effector.surfaceArc = 0; } else { jump = true; } } if (Input.GetKeyUp("s")) { changePlatformState = true; } if (!this.GetComponent <Collider2D>().Distance(platform.GetComponent <Collider2D>()).isOverlapped&& changePlatformState) { PlatformEffector2D effector = platform.GetComponent <PlatformEffector2D>(); effector.surfaceArc = 180; changePlatformState = false; } if (Input.GetButtonDown("Crouch")) { crouch = true; } else if (Input.GetButtonUp("Crouch")) { crouch = false; } if (canDash) { if (Input.GetButtonDown("Dash")) { if (Input.GetAxisRaw("Horizontal") > 0) { dashDirection = DashDirection.Right; dashing = true; canDash = false; } else if (Input.GetAxisRaw("Horizontal") < 0) { dashDirection = DashDirection.Left; dashing = true; canDash = false; } } } if (Time.time >= nextAttackTime) { if (Input.GetMouseButtonDown(0)) { attacking = true; nextAttackTime = Time.time + 1f / attackRate; } } if (Input.GetButtonDown("Interact")) { Collider2D[] interact = Physics2D.OverlapCircleAll(interactHitbox.position, interactRange, interactableLayer); foreach (Collider2D inter in interact) { inter.GetComponent <Interactable>().activate(); } } }
public void SetDashDir(DashDirection dir) { dashDir = dir; }
// Start is called before the first frame update void Start() { jebseeController = gameObject.GetComponent <BasicCharacterControler>(); body = GetComponent <Rigidbody2D>(); dashDirection = DashDirection.NoDirection; }