Hello everyone.
Im trying to create a knockback effect.
So, I have 2 gameObjects.
1)Player
2)Ball
What I want to accomplish is to randomly create a ball that moves towards the player, when hit, the player must move “back” from where it was hit.(As like following the path of the ball).
What I was trying was :
void OnCollisionEnter2D(Collision2D other) {
Debug.LogWarning ("Player Collision");
if (other.gameObject.tag.Equals("Ball"))
{
_playerRigidB.AddForce(other.rigidbody.velocity * 1);
Debug.Log ("Pushing");
}
Debug.Log ("done");
}
But it doesn’t seem to be working. Am I doing this correctly?
Thanks for your time.