Hello everyone, I’m trying to lerp between two values.
if(gameObject.transform.position != endPos)
{
float currentDuration = Time.time - lerpStartTime;
float journeyFraction = currentDuration / totalDistanceToDestination;
gameObject.transform.position = new Vector3(Mathf.Lerp (startPos.x, endPos.x, journeyFraction * 2f), gameObject.transform.position.y, gameObject.transform.position.z);
print("posX: " + gameObject.transform.position.x);
}
else if(gameObject.transform.position == endPos) { lerping = false; alreadySwiped = false;}
This is the code i’m using. So, the problem is, it never gets tot the end of the “endPos.x”.
For a better understanding, here is the output of the print in the first if statement:
starPos = (24.3, -22.5, -11.7)
endPos = (31.9, -22.5, -11.7)
posX: 30.9175
posX: 31.33167
posX: 31.74583
posX: 31.86094
posX: 32.16732 -- Here it goes over the maximum value.
posX: 31.86094 -- Here it goes to the final value again.
posX: 32.58005 -- Again, but this time the number is bigger.
posX: 31.86094
posX: 32.99336
posX: 31.86094
posX: 33.40636 -- And it just goes on like this, and never stops.
I’m out of Ideas. I tried Vector3.Lerp too, the output is the same. I’m happy for every suggestion you may have. Thank you.