Question by
dhawal96 · Oct 19, 2017 at 03:26 AM ·
animationunity 52d-platformerdash
Dash Cooldown is cancelling AddForce
I am trying to make my enemy dash and attack my player, but with a cooldown. Currently, the cooldown works but I cannot get the enemy animation to move with addForce. If I remove cooldown, then my animation moves through addForce. How can I fix this?
void Update() {
switch (dashState)
{
case DashState.Ready:
savedVelocity = rb2d.velocity;
dashState = DashState.Dashing;
break;
case DashState.Dashing:
if (Player.GetComponent<Player>().dead == true)
{
anim.SetBool("Dash", false);
dashState = DashState.End;
}
else
{
rb2d.isKinematic = false;
anim.SetBool("Dash", true);
if (transform.localScale.x > 0)
{
rb2d.AddForce(Vector3.right * 50f);
}
else
{
rb2d.AddForce(Vector3.left * 50f);
}
rb2d.velocity = savedVelocity;
nextFire = Time.time + fireRate; // fireRate is 5f and nextFire is initially 0f
dashState = DashState.Cooldown;
}
break;
case DashState.Cooldown:
anim.SetBool("Dash", false);
if (Time.time > nextFire)
{
dashState = DashState.Ready;
}
break;
default:
break;
}
}
Comment
I'm trying to make enemy dash in 3d-dungeon game but i don't know how to do it.
Your answer
Follow this Question
Related Questions
Animation delay on android? 0 Answers
How too climb a ladder with the FPS Controller correctly 0 Answers
Game runs fine in unity but lags terribly in VS build 0 Answers
Control the value of an animation with a slider 0 Answers
Can't get animator to activate parameter more than once (Unity2D). 0 Answers