I’m making a RPG with an “attack speed” stat which is added as a speed multiplier for the animation. When I then go in game the animation looks good when attack speed is 1.0 but when it I set it to 2.0 the animation gets faster but considerably shorter. I haven’t done a lot of animating so I suspect it can be in my animation handler code. Does anyone know where the problem might be?
Animation handler code:
void Update ()
{
//update variables
UsingMagic = animator.GetBool("UseMagic");
AttackDone = (!startedAnimation && animator.GetBool("Attack") && !animator.IsInTransition(0) &&
animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= animator.GetCurrentAnimatorStateInfo(0).length);
//manage animations
if (AttackDone && !UsingMagic)
{
AttackReset();
}
//reset started animation variable
if (animator.GetCurrentAnimatorClipInfo(0)[0].clip.name != "PlayerMelee" || animator.GetCurrentAnimatorClipInfo(0)[0].clip.name != "PlayerMagic")
{
startedAnimation = false;
}
}
/// <summary>
/// Play attack animation using attack speed if melee
/// </summary>
/// <param name="attackSpeed">the speed of the melee animation</param>
public void Attack (float attackSpeed)
{
if (!animator.IsInTransition(0) && !animator.GetBool("Attack") &&
!animator.GetCurrentAnimatorStateInfo(0).IsName("PlayerMelee") &&
!animator.GetCurrentAnimatorStateInfo(0).IsName("PlayerMagic"))//don't interrupt
{
animator.SetBool("Attack", true);
animator.SetFloat("AttackSpeed", attackSpeed);
startedAnimation = true;
}
}
Attack code:
if (Input.GetButton("Fire1") && !UsingMagic && weaponEquiped != null)
{
animHandler.Attack(stats.AttackSpeed);
//Debug.Log("MeleeAttack");
}