basically my code is working fine and all is good. My only problem is that the character is changing position is splits of seconds from this line
float perc = currentLerpTime / lerpTime;
var _CurrentPosition = gameObject.transform.position.x;
var DesiredPosition = Mathf.Lerp (_CurrentPosition, _CurrentPosition + evadeForce, perc);
gameObject.transform.position = new Vector2 (DesiredPosition, gameObject.transform.position.y);
the code above gets current position then lerps to new position then applies it. but it is happening too fast like the player is disappearing. instead i want it to be slower.
basically instead of going from A to B in 0.1 seconds I want it to go from A to B in 1 second.
Here is the full code:
IEnumerator _EvadeAttacks()
{
Physics2D.IgnoreLayerCollision(playerLayer, EnemyLayer, true);
currentLerpTime = 0f;
currentLerpTime += Time.deltaTime;
if (currentLerpTime > lerpTime) {
currentLerpTime = lerpTime;
}
if (!evadeLeft)
{
Debug.Log ("workingright");
float perc = currentLerpTime / lerpTime;
var _CurrentPosition = gameObject.transform.position.x;
var DesiredPosition = Mathf.Lerp (_CurrentPosition, _CurrentPosition + evadeForce, perc);
gameObject.transform.position = new Vector2 (DesiredPosition, gameObject.transform.position.y);
hasEvaded = true;
} else if (evadeLeft)
{
Debug.Log ("workingleft");
float perc = currentLerpTime / lerpTime;
var _CurrentPosition = gameObject.transform.position.x;
var DesiredPosition = Mathf.Lerp (_CurrentPosition, _CurrentPosition - evadeForce, perc);
gameObject.transform.position = new Vector2 (DesiredPosition, gameObject.transform.position.y);
hasEvaded = true;
}
canWalk = true;
yield return new WaitForSeconds(SecondsToWaitForEvadeCollider);
Physics2D.IgnoreLayerCollision(playerLayer, EnemyLayer, false);
yield return new WaitForSeconds (SecondsToWaitForEvadeReset);
hasEvaded = false;
}