- Home /
The way to approach DodgeRoll
The player moves towards the key directions wherever is targeting the enemy or not. The only diference is that when targeting the player is always facing the enemy.
The intention is when targeting, if the player dodge to the left or right he dodge 4meters around the target and forward or back 4 meters in the direction of the target or away.
This is how far i got..
//Dodge Forward if (Input.GetButtonDown("Vertical") && Input.GetAxis("Vertical") > 0 && (playerController.collisionFlags & CollisionFlags.Below) != 0 && Input.GetAxis("Horizontal") == 0) { if (Input.GetButtonDown("Vertical") && (Time.time - lastTime) < 0.5f && Input.GetButtonDown("Vertical") && (Time.time - lastTime) > 0.1f && Input.GetAxis("Vertical") > 0.03f) { lastTime = Time.time;
if (isTargetLocked) {
//direction = Vector3.forward;
direction = (target.transform.position - playerController.transform.position).normalized;
destinationDistance = (playerController.transform.position) + direction * 4;
StartCoroutine(TargetDodgeRoll());
}
if (!isTargetLocked) {
destinationDistance = playerController.transform.position + Vector3.forward * 4;
StartCoroutine(DodgeRoll());
}
Debug.DrawLine(playerController.transform.position, destinationDistance, Color.red, 10f);
//destinationDistance = playerController.transform.position + new Vector3(0f, 0f, 4f);
StartCoroutine(DodgeRoll());
isDodging = false;
} else
lastTime = Time.time;
}
public IEnumerator TargetDodgeRoll() {
while (!Mathf.Approximately((playerController.transform.position - destinationDistance).sqrMagnitude, 0)) {
isDodging = true;
if (!isDestination && isTargetLocked == true) {
Quaternion targetRotation = Quaternion.LookRotation(target.transform.position - playerController.transform.position);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSmoothing * Time.deltaTime);
playerController.transform.position = Vector3.MoveTowards((playerController.transform.forward), destinationDistance, dodgeSpeed * Time.deltaTime);
Debug.Log("Destination: " + !Mathf.Approximately((playerController.transform.position - destinationDistance).sqrMagnitude, 0));
yield return null;
} else {
yield return null;
}
}
The distinationDistance is correct but the direction the player goes is wrong. Also i couldn't figure out how to move around the target 4 meters at fixed orbit.
Thank you