I’m trying to apply a knockback to the player after he is hit by the enemy. They’re both rigidbodies so I thought it shouldn’t be that hard. For debug purposes I’ve set it so it does it everytime they collide.
Here’s the code:
void OnTriggerEnter (Collider other)
{
// If the entering collider is the player…
if(other.gameObject == player)
{
this.rigidbody.AddForce(target.rigidbody.velocity * force);
// … the player is in range.
playerInRange = true;
}
}
Force is set to be a public int and is set to 200 atm in unity.
Nothing happens. I’m sure the colliders are setup right because playerInRange gets set to true.
What could be the problem?