Make enemy GameObject move on collision

I am trying to make an enemy’s game object go flying when it collides with the player. Kinematic is disabled on both the player and the enemy object.

I have this code in the enemy’s class:

void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == “Player”) {
Vector3 dir = collision.contacts[0].point - transform.position;
dir = -dir.normalized;
GetComponent().AddForce(dir * 100);
}
}

However, while the enemy object does detect the collision, I do not see it react with the force of the Player.

Any ideas on what could be happening?

hard to say :confused: your code does look fine. One thing is to check the mass of your enemy, 100 force might seem like a lot but not if its mass is high.

otherwise check for instances in your enemies code for things like rigidbody.Velocity = X since that will overwrite any force changes once its called.

Also worth checking for things like transform.position = X