Question by
Peepo · Oct 05, 2021 at 07:37 PM ·
updateaddforceontriggerenter2d
Add Force Against the Player only Works after I Press the attack Button
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Enemy"))
{
Enemy enemy = other.GetComponent<Enemy>();
enemy.damage -= stats.health;
Debug.Log("KnockBack");
Vector3 dir = (rb.transform.position - other.transform.position).normalized;
rb.AddForce(dir * enemy.knockBack, ForceMode2D.Impulse);
}
}
It recognizes when I enter the trigger (found through debug mode) but it does not apply force to my character until after I press the attack button. The health part updates instantly however...
I do not have the same problem with the enemies knockback which is coded the same way.
basically: can knock back enemies but the enemies cannot knock me back until I swing my sword.
Comment