This question was
closed Jan 24, 2019 at 07:00 AM by
NerdIt- for the following reason:
The c# was not starting the cooldown fast enough.
Question by
NerdIt- · Jan 24, 2019 at 06:48 AM ·
c#ienumeratoraddrelativeforce
AddRelativeForce is adding to much force.
I have made a script that dashes forwards using AddRelativeForce. I have set up an IEnumerator to make a cooldown function of 4 seconds. The dash function is run when the user left clicks. The issue is once you left click and wait for the 4 seconds cooldown to be over, the next time you try to run dash function it adds way to much force.
The parts of the script that involve the dash function are:
if (Input.GetKey(KeyCode.Mouse0) & dashAttackCoolDown == false)
{
rigid.AddRelativeForce(-Vector3.forward * 11050);
dashAttackCoolDown = true;
}
if (dashAttackCoolDown)
{
StartCoroutine(DashCoolDown());
}
IEnumerator DashCoolDown()
{
yield return new WaitForSeconds(4);
dashAttackCoolDown = false;
}
Comment
yeah, you forgot to realize that if you add force while the body has velocity, you increase the velocity beyond the originally intended one, which you realized later which is why you closed the question, right? :)