void punch() { if (readyToAttack) { punching = true; Vector3 start = transform.position + transform.up; Vector3 end; if (facingRight) { end = start + punchReach * transform.right; } else { end = start + punchReach * -transform.right; } Vector2 punchDir = end - start; if (Physics2D.Linecast(start, end)) { enemyrb.AddForceAtPosition(punchDir.normalized * punchPower, start); source.Play(); JoScript.takeDamage(punchDamage); } } }
void kick() { if (readyToAttack) { kicking = true; Vector3 start = transform.position + transform.up; Vector3 end; //special crouching kick if (crouching) { if (facingRight) { end = start + kickReach * transform.right; } else { end = start + kickReach * -transform.right; } Vector2 kickDir = end - start; if (Physics2D.Linecast(start, end)) { enemyrb.AddForceAtPosition(kickDir.normalized * kickPower, start); source.Play(); JoScript.takeDamage(kickDamage); } } //normal standing upright kick else { if (facingRight) { end = start + kickReach * (transform.right + transform.up); } else { end = start + kickReach * (-transform.right + transform.up); } Vector2 kickDir = end - start; if (Physics2D.Linecast(start, end)) { enemyrb.AddForceAtPosition(kickDir.normalized * kickPower, start); source.Play(); JoScript.takeDamage(kickDamage); } } } }