I've had a look around tigsource and the internet in general and haven't found much in the way of help so hopefully this isn't doubling up on a discussion somewhere.
Recently I watched juice it or lose it and have been trying to implement easing formula in C# and Unity and it's is really doing my head in. Hopefully someone here can help.
I've found a couple of sources for formula already formatted for C# but the one that makes the most sense is this one:
https://gist.github.com/xanathar/735e17ac129a72a277eeand here's my code
void Update () {
intermediaryPos = gameObject.transform.localPosition;
if (time < duration)
{
time += Time.deltaTime * timeMultiplier;
gameObject.transform.localPosition = new Vector3(Easing.CircEaseInOut(time, currentPosX, destinationPosX, duration), transform.position.y, transform.position.z);
}
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
currentPosX = intermediaryPos.x;
destinationPosX = destinationPosX - speed;
time = 0f;
}
else if (Input.GetKeyDown(KeyCode.RightArrow))
{
currentPosX = intermediaryPos.x;
destinationPosX = destinationPosX + speed;
time = 0f;
}
}
I think I understand what it's doing but I've been really struggling to implement it without any erroneous behavior. Basically what is happening is when i press left or right arrows once, and allow the object to reach its destination then press the opposite direction nothing happens till i press it a second time. So in this case the formula doesn't move the value from whatever back to 0.
Also what happens when i press the same direction more than once is that the second time the object will move twice as far as it did the first time.
Is anyone here able to point me in the right direction?