#attack move animation issue
1 messages · Page 1 of 1 (latest)
Sorry for the delay, I had to walk away.
yield return new WaitForSeconds(2f);
is the same as
float time = 0f;
while(time < 2f)
{
time += Time.deltaTime;
yield return null;
}
assuming they're both inside a coroutine
So, you're problem right now is that you run the line:
player.transform.position = Vector3.MoveTowards(playerStartPoint.position, playerAttackVector[2], playerMovementSpeed * Time.deltaTime);
one time, then you start the coroutine TimingSwordAttack, and that has a bunch of yield return new WaitForSeconds in it that make it take multiple frames.
instead, you need to move that line inside of a coroutine in a while loop
something like:
float timeElapsed = 0f;
while(timeElapsed < 2f)
{
timeElapsed += Time.deltaTime;
player.transform.position = Vector3.MoveTowards(
player.transform.position,
playerAttackVector[2],
playerMovementSpeed * Time.deltaTime);
yield return null;
}
except now that it is inside of a coroutine, you could use Lerp instead. That would probably be cleaner. MoveTowards as you have it set up is more suited to be used in Update.