Hi, I’m working on a game in which the player can freeze time and place up to three destinations (stored in array) and then dash through them in sequence. I’ve got dash working but it seems to be curving through the from the starting position to the last destination rather than going from point to point. Any help would be appreciated!
void SetDestinations()
{
if (dashNumber < 3)
{
dashMarks[dashNumber].transform.position = dashDestination;
dashMarks[dashNumber].SetActive(true);
dashOrigin = dashMarks[dashNumber].transform.position;
dashNumber++;
}
}
void TriggerDashes()
{
dashNumber = 0;
foreach (GameObject gameObject in dashMarks)
{
if (dashMarks[dashNumber].transform.position != Vector3.zero)
{
StartCoroutine(LerpDash(dashMarks[dashNumber].transform.position, dashSpeed));
dashMarks[dashNumber].SetActive(false);
dashMarks[dashNumber].transform.position = Vector3.zero; //reset position to limit next dashes
dashNumber++;
}
}
}
IEnumerator LerpDash(Vector3 targetPosition, float duration) //still seems to be smoothing between points?
{
float time = 0;
while (time < duration)
{
transform.LookAt(targetPosition);
transform.position = Vector3.Lerp(transform.position, targetPosition, time / duration);
time += Time.deltaTime;
yield return null;
}
transform.position = targetPosition; //snapping
}