So I have this scene, where I have a player that can shoot bullets at an enemy. I want to AddForce to the RigidBody2D of the enemy when the bullet hits, but until now I have no success.
My bullet script:
void Update()
{
theRB.velocity = transform.right * speed;
}
private void OnTriggerEnter2D(Collider2D other)
{
Instantiate(impactEffect, transform.position, transform.rotation);
Destroy(gameObject);
if (other.tag == "Enemy")
{
other.GetComponent<EnemyHealthController>().DamageEnemy(damageToGive);
}
}
Where do I put the Addforce function? Do I have to get a reference from the enemy RigidBody on my Bullet Script?
I’m kinda new to unity so any help is much appreciated!
Thanks in advance.
PS: I’m trying to make to a topdown shooter game.