- Home /
Question by
deadsea2004 · Nov 03, 2018 at 03:41 AM ·
2d gameshootertop-downknockback
[2D] Adding force in a radius around player
I am making a top-down shooter with a knockback mechanic where, upon the press of a key, the player will knockback surrounding enemies.
Right now, I am activing a "BashRadius" object under my parent Player object upon pressing RMB. This BashRadius has a trigger collider as well as a script on it which checks OnTriggerEnter2D.
How does one trigger a knockback effect on enemies which enters this trigger circle?
private void OnTriggerEnter2D(Collider2D collision)
{
if (tags == null)
return;
if (tags.Contains("destructible") || tags.Contains("enemy"))
{
//Knockback here
if (tags.Contains("destructible"))
{
//Deal minor damage here
collision.gameObject.GetComponent<Destructible>().DealDamage(damage);
}
if (tags.Contains("enemy"))
{
collision.gameObject.GetComponent<Enemy>().DealDamage(damage);
}
}
}
Comment