The effect is - Upper ball moved, moving ball bounced back

[/code]

Yes. There is something wrong with your code.

If the incoming ball just collide with the upper one, it should move into the direction to collide with the second ball. (The incoming ball should not bounced back???).

In real life,usually, the incoming ball will hit one of the ball first then collide with the second one.

If you want to simulate the incomng ball collide with the other two balls at the same time:

Assume the incoming ball with initial valocity ,

Since the size of the balls are the same, and they all have the same mass.

If the incoming ball hit the other two balls at the same time, the interactive force between incoming ball and any one of the ball are in the direction connect two center of the ball.

So the direction is 45 degree or -45 degree. It means that the force is the same in x direction and in y direction. So the momentum change in x/y diretion are the same.

So the velocity for the other two balls just after the collision are

and

and assume the velocity for the incoming ball after the collision is

Conservation of momentum:

Conservation of energy:

which imply

So the result are:

which mean that the incoming ball with initial velocity will be stopped () just after the collision, and the other two balls will move with velocity

and

However, this kind of situation normally will not happened in real life.