So, I have an object which I want to move with values given in the inspector, for example I want the object to travel 1 unit with a 3 second time. Here’s what I’m using:
This executes if isR1InUse is true (it keeps executing in the Update function of the base class) and only stops when the same variable is set to false as I do it in the code below when the time ends.
It does three seconds but the object travels way more than just one unit. What am I doing wrong?
protected override void MeleeAttack()
{
Vector3 startingPos = meleeWeapon.transform.localPosition;
meleeWeapon.transform.localPosition
= Vector3.Lerp(startingPos, startingPos += new Vector3(0, 0, maxMeleeDistance), meleeAttackSpeed * Time.deltaTime);
timeElapsed += Time.deltaTime;
if (timeElapsed >= meleeAttackSpeed)
{
isR1InUse = false;
timeElapsed = 0;
}
}