KnockBack Effect.

Hello everyone.
Im building a 2D small game.

I’ve created an object in the middle of the screen.

I’ve created a button that spawns 2 types of balls that moves towards the center. Green and Red balls.

How can I create an effect that manages to knockback the gameObject in the middle of the screen when GREEN balls touch the ball.

Originally I had attached a script to the gameObject that has :

void OnCollisionEnter2D(Collision2D other) {
		Debug.LogWarning ("Player Collision");
              //if(other.tag == "greenBall")
                   //KnockBackEffect()
}

The problem is that I initially used transform.position but as the balls come from different areas I was wondering if there’s something already built-in unity, if so, how to use it.

Thanks for your help && time!

I’m not completely sure on how to do it, but you might want to try using rigidbody.Moveposition for your objects, since transform.position to my knowledge ignores physics… If you use that, you could use rigidbody.Addforce. I found a question similar to yours which might help you using rigid bodies: