Hi there,
I have a character who can perform some basic attacks. If a key is pressed, he’ll swipe his sword, if the same key is pressed within a few milliseconds after that first swipe, he’ll perform a second swipe. Finally, if the same key is pressed again for a third and final time after that second swipe, he’ll perform a spinning strike. So I basically have a combo going on here.
The problem is, after the third swipe, my character moves position, but then reverts back to his old position after the animation. Now I’ve read that this has to do with the player’s mesh moving, but not the gameObject itself. I just can’t figure out a solution of how to update his position after the strike. Here’s a snippet of my code that focuses on the attacks:
if (Input.GetKeyDown (KeyCode.B) && firstSlash == false && secondSlash == false && SwordCollect.swordObtained == true && blocking == false && attacking==false && HealthController.flinch==false) {
blocking = false;
StartCoroutine (attack ());
} else if (Input.GetKeyDown (KeyCode.B) && firstSlash == true && attacking==false && HealthController.flinch==false) {
blocking = false;
StartCoroutine (attack2 ());
} else if (Input.GetKeyDown (KeyCode.B) && secondSlash == true && attacking==false && HealthController.flinch==false) {
blocking = false;
StartCoroutine (attack3 ());
IEnumerator attack (){
attacking = true;
animation.CrossFade ("slash",0.2f);
audio.PlayOneShot(slash1);
yield return new WaitForSeconds (animation ["slash"].length);
attacking = false;
firstSlash = true;
yield return new WaitForSeconds (0.2f);
firstSlash = false;
}
IEnumerator attack2 (){
attacking = true;
animation.CrossFade ("slash2",0.2f);
audio.PlayOneShot(slash2);
yield return new WaitForSeconds (animation ["slash2"].length);
attacking = false;
secondSlash = true;
yield return new WaitForSeconds (0.2f);
secondSlash = false;
}
IEnumerator attack3 (){
attacking = true;
animation.CrossFade ("slash3",0.2f);
audio.PlayOneShot(slash3);
yield return new WaitForSeconds (animation ["slash3"].length);
attacking = false;
}
Any help or advice would be much appreciated.
Thanks in advance.