Hey, I need to calculate the time it takes for my player to reach a destination so I can adjust the animation speed.
so I thought I could just use Time = Distance / Speed, but this doesn't seem to be working.
When I subtract the starting time from the current time I get a different outcome that seems to also be the correct time it takes to reach the destination.
At first I thought Time.deltaTime could be the cause but I found a forum post that says what I am doing should work but that post might be wrong.
The forum post in question.
minClimbDistance is set to 0.01f and is not the issue, I tried changing it to this.transform.position != climbDestination but the issue remained.
private IEnumerator LedgeClimb()
{
float startTime = Time.time;
currentClimbDistance = Vector3.Distance(this.transform.position, climbDestination);
headAnimator.speed = currentClimbDistance / climbSpeed + 1;
print(currentClimbDistance / climbSpeed);
while (currentClimbDistance > minClimbDistance)
{
this.transform.position = Vector3.MoveTowards(this.transform.position, climbDestination, climbSpeed * Time.deltaTime);
currentClimbDistance = Vector3.Distance(this.transform.position, climbDestination);
yield return null;
}
print("Climb Time: " + (Time.time - startTime));
}
Any help with this would be much appreciated, thank you for reading!