private void LateUpdate() { if (!healthHandler.afflictedStatus.Contains(Lists.Status.SpellLocked)) { if (!dashing) { if (Input.GetKeyDown(KeyCode.W)) { dashCounter[0]++; StartCoroutine(DashTimer(0)); if (dashCounter[0] >= 2) { movingTransform.localRotation = Quaternion.Euler(0, 0, 0); StartCoroutine(Dash(myTransform.forward)); } } if (Input.GetKeyDown(KeyCode.D)) { dashCounter[1]++; StartCoroutine(DashTimer(1)); if (dashCounter[1] >= 2) { movingTransform.localRotation = Quaternion.Euler(0, 90, 0); StartCoroutine(Dash(myTransform.right)); } } if (Input.GetKeyDown(KeyCode.S)) { dashCounter[2]++; StartCoroutine(DashTimer(2)); if (dashCounter[2] >= 2) { movingTransform.localRotation = Quaternion.Euler(0, 180, 0); StartCoroutine(Dash(-myTransform.forward)); } } if (Input.GetKeyDown(KeyCode.A)) { dashCounter[3]++; StartCoroutine(DashTimer(3)); if (dashCounter[3] >= 2) { movingTransform.localRotation = Quaternion.Euler(0, 270, 0); StartCoroutine(Dash(-myTransform.right)); } } } } //Faz o personagem olhar na direcao correta if (!dashing) { if (healthHandler.afflictedStatus.Contains(Lists.Status.SpellLocked) && shouldLook) { facingPoint = (myTransform.forward * 10000) + myTransform.position; if (facingPoint != Vector3.zero) { facingPoint.y = facingTransform.position.y; targetRotation = Quaternion.LookRotation(facingPoint - facingTransform.position, myTransform.up); targetRotation = Quaternion.Euler(facingTransform.eulerAngles.x, targetRotation.eulerAngles.y, facingTransform.eulerAngles.z); lerpRotation = Quaternion.Lerp(lerpRotation, targetRotation, 0.2f); facingTransform.rotation = lerpRotation; localRotation = facingTransform.localRotation; float dotValue = Vector3.Dot(movementDirection, facingTransform.forward); if (dotValue > 0.3f) { //forward facingDirection = 0; movingTransform.localRotation = Quaternion.Lerp(movingTransform.localRotation, Quaternion.Euler(0, Formulas.AngleAroundAxis(myTransform.forward, movementDirection, Vector3.up), 0), 0.2f); } else if (dotValue > -0.3f) { //sides float crossValue = Vector3.Cross(movementDirection, facingTransform.forward).y; if (crossValue > 0.9f) { //right facingDirection = 1; movingTransform.localRotation = Quaternion.Lerp(movingTransform.localRotation, Quaternion.Euler(0, 0, 0), 0.2f); } else if (crossValue < -0.9f) { //left facingDirection = 3; movingTransform.localRotation = Quaternion.Lerp(movingTransform.localRotation, Quaternion.Euler(0, 0, 0), 0.2f); } } else { //backwards facingDirection = 2; movingTransform.localRotation = Quaternion.Lerp(movingTransform.localRotation, Quaternion.Euler(0, Formulas.AngleAroundAxis(myTransform.forward, -movementDirection, Vector3.up), 0), 0.2f); } } //if (moving) { Vector3 tempCamPos = new Vector3(mainCamTransform.position.x, myTransform.position.y, mainCamTransform.position.z); Vector3 faceDir = (myTransform.position - tempCamPos).normalized; myTransform.forward = Vector3.Lerp(myTransform.forward, faceDir, 0.5f); } } else { facingDirection = 0; localRotation = Quaternion.Lerp(localRotation, Quaternion.Euler(270, 90, 0), 0.2f); // Quaternion.identity; facingTransform.localRotation = localRotation; lerpRotation = facingTransform.rotation; if (moving) { Vector3 tempCamPos = new Vector3(mainCamTransform.position.x, myTransform.position.y, mainCamTransform.position.z); Vector3 faceDir = (myTransform.position - tempCamPos).normalized; myTransform.forward = Vector3.Lerp(myTransform.forward, faceDir, 0.2f); movingTransform.localRotation = Quaternion.Lerp(movingTransform.localRotation, Quaternion.Euler(0, Formulas.AngleAroundAxis(myTransform.forward, movementDirection, Vector3.up), 0), 0.2f); } else { movingTransform.localRotation = Quaternion.Lerp(movingTransform.localRotation, Quaternion.Euler(0, 0, 0), 0.2f); } } } }