void FixedUpdate() { if (!GameManager.GamePaused) { if (!isDashing) { moveHorizontal = Input.GetAxis("Horizontal"); moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal * movementSpeed, 0.0f, moveVertical * movementSpeed); if (movement != Vector3.zero) { rb.velocity = movement; rb.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement.normalized), 0.2f); //Dash if (Input.GetKeyDown(KeyCode.Space) && dashCooldown.IsCoolDownCompleted) { isDashing = true; Instantiate(DashEffect, transform.position, Quaternion.identity); dashCooldown.SetCooldown(); } } } else { if (dashTime < 0) { //the dash has just finished isDashing = false; dashTime = startDashTime; rb.velocity = Vector3.zero; } else { //is dashing dashTime -= Time.deltaTime; Vector3 movement = new Vector3(System.Math.Sign(moveHorizontal) * dashSpeed, 0.0f, System.Math.Sign(moveVertical) * dashSpeed); rb.velocity = movement; } } } }
void FixedUpdate() { if (!isDashing) { moveHorizontal = Input.GetAxis("Horizontal"); moveVertical = Input.GetAxis("Vertical"); Vector2 movement = new Vector2(moveHorizontal, moveVertical); if (movement != Vector2.zero) { rb2d.MovePosition(rb2d.position + movement * speed * Time.deltaTime); //Dash if (Input.GetKeyDown(KeyCode.Space) && dashCooldown.IsCoolDownCompleted) { isDashing = true; Instantiate(DashEffect, transform.position, Quaternion.identity); dashCooldown.SetCooldown(); } } } else { if (dashTime < 0) { //the dash has just finished isDashing = false; dashTime = startDashTime; rb2d.velocity = Vector3.zero; } else { //is dashing dashTime -= Time.deltaTime; Vector2 movement = new Vector2(System.Math.Sign(moveHorizontal), System.Math.Sign(moveVertical)); movement.Normalize(); rb2d.MovePosition(rb2d.position + movement * dashSpeed * Time.deltaTime); } } }