Hi,
How do I make an enemy to be pushed in a opposite direction of the bullet while being hit?
tried to do this:
public GameObject Projectile_DEFAULT;
float force = 60f;
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Fireball_DEF")
{
Vector2 PushDirection = (transform.position - Projectile_DEFAULT.transform.position);
gameObject.GetComponent<Rigidbody2D>().AddForce(PushDirection * force);
}
}
but it’s only pushing the enemy in one direction (right) no matter if the enemy was hit from left or right, so, what should i do there?