Push back an enemy on trigger
I have two gameobjects, one of them is my "hero" an the other one the enemy with a NavMesh, I've managed to make the health system without problems but know when the sword collides with the enemy it seems that the rigidbody is not working or something because I've tried a couple of solutions that I've found on Internet but nothing seem to work. I want the enemy to be pushed once the sword collides with it. I've tried this:
public void takeDamage() {
// revert rigidbody velocity:
rigidbody.velocity *= -1;
}
Another code
float distance = 25.0f;
if (player.position.x < enemyPosition.position.x) {
Vector3 new_position = new Vector3 (enemyPosition.position.x + distance, enemyPosition.position.y, enemyPosition.position.z);
rb.position = new_position;
}
Thanks
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612074434im_/https://answers.unity.com/themes/thub/images/avi.jpg)