private void ExecuteDodge(DodgeDirection direction) { currentState = PlayerState.dodging; currentDodgeDirection = direction; float xyDodgeLength = Mathf.Sqrt((playerShip.dodgeLength * playerShip.dodgeLength) / 2); //IEnumerable coroutine = Dodge (); switch (direction) { case DodgeDirection.E: currentDodgeTarget = this.gameObject.transform.position + new Vector3(0, playerShip.dodgeLength); break; case DodgeDirection.N: currentDodgeTarget = this.gameObject.transform.position + new Vector3(-playerShip.dodgeLength, 0); break; case DodgeDirection.W: currentDodgeTarget = this.gameObject.transform.position + new Vector3(0, -playerShip.dodgeLength); break; case DodgeDirection.S: currentDodgeTarget = this.gameObject.transform.position + new Vector3(playerShip.dodgeLength, 0); break; case DodgeDirection.NE: currentDodgeTarget = this.gameObject.transform.position + new Vector3(-xyDodgeLength, xyDodgeLength); break; case DodgeDirection.SE: currentDodgeTarget = this.gameObject.transform.position + new Vector3(xyDodgeLength, xyDodgeLength); break; case DodgeDirection.NW: currentDodgeTarget = this.gameObject.transform.position + new Vector3(-xyDodgeLength, -xyDodgeLength); break; case DodgeDirection.SW: currentDodgeTarget = this.gameObject.transform.position + new Vector3(xyDodgeLength, -xyDodgeLength); break; } InvokeRepeating("playerEcho", 0f, 0.03f); }
private static void CheckForDoubleTapDodge(bool isTap, ref DateTime?lastTapRegistered, DodgeDirection dodgeDirection) { if (isTap) { var milliesSinceLastTap = (DateTime.Now - lastTapRegistered)?.TotalMilliseconds ?? DodgeDoubleTapDelay.Value; if (milliesSinceLastTap < DodgeDoubleTapDelay.Value) { DodgeDir = dodgeDirection; } else { lastTapRegistered = null; } if (lastTapRegistered == null) { lastTapRegistered = DateTime.Now; } } }
public void Dodge(Transform transform, DodgeDirection direction) { Vector3 targetPosition = transform.position + transform.right * (int)direction * distance; transform.position = Vector3.Lerp(transform.position, targetPosition, (Time.time - startTime) * transitionSpeed * Time.deltaTime); }
IEnumerator Dodge(DodgeDirection dir) { Debug.Log("Dodging"); GetComponent <PlayerAvatar> ().Invincible = true; float timer = 0f; float maxTimer = 0.25f; delayD = 0; dodgeNotif.text = "DO A BARREL ROLL!!"; dodgeSoundEffect.Play(); switch (dir) { //up case DodgeDirection.up: Debug.Log("dodge up"); GetComponent <PlayerAvatar>().CurEnergy -= 5; while (timer < maxTimer) { StartCoroutine(BlinkDodge()); rb.transform.Rotate(new Vector3(0, 1440 * Time.deltaTime, 0)); rb.transform.position = new Vector3(transform.position.x, transform.position.y + speed * 0.75f * Time.deltaTime, 0); timer += Time.deltaTime; yield return(null); } break; //down case DodgeDirection.down: Debug.Log("dodge down"); GetComponent <PlayerAvatar>().CurEnergy -= 5; while (timer < maxTimer) { StartCoroutine(BlinkDodge()); transform.Rotate(new Vector3(0, -1440 * Time.deltaTime, 0)); transform.position = new Vector3(transform.position.x, transform.position.y - speed * 0.75f * Time.deltaTime, 0); timer += Time.deltaTime; yield return(null); } break; //left case DodgeDirection.left: Debug.Log("dodge left"); GetComponent <PlayerAvatar>().CurEnergy -= 5; while (timer < maxTimer) { StartCoroutine(BlinkDodge()); transform.Rotate(new Vector3(-1440 * Time.deltaTime, 0, 0)); transform.position = new Vector3(transform.position.x - speed * 0.5f * Time.deltaTime, transform.position.y, 0); timer += Time.deltaTime; yield return(null); } break; //right case DodgeDirection.right: Debug.Log("dodge right"); GetComponent <PlayerAvatar>().CurEnergy -= 5; while (timer < maxTimer) { StartCoroutine(BlinkDodge()); transform.Rotate(new Vector3(1440 * Time.deltaTime, 0, 0)); transform.position = new Vector3(transform.position.x + speed * 0.5f * Time.deltaTime, transform.position.y, 0); timer += Time.deltaTime; yield return(null); } break; } timer = 0f; yield return(new WaitForSeconds(0.2f)); GetComponent <PlayerAvatar> ().Invincible = false; dodgeNotif.text = ""; }