Suppose a circle is enclosed in a diamond, and the circle heads due right. I would expect a series of continual 90 degree angles as the circle draws a square within the diamond.
What I'm seeing, however, is that the circle eventually gets pushed toward the center of the diamond after one or two collisions. What's going on?
The line is set to dynamic -> NO.
The ball gets reflected symmetrically to its angle of approach assuming it's a completely elastic collision. That means, to get the behavior you are looking for, the ball would need to approach exactly from one line mid-point to the next without any loss of energy.
Sprite Kit's physics engine will not be able to handle these exact values. The energy after an elastic collision in Sprite Kit is not guaranteed to be conserved. There will be small inaccuracies in the physics engine's floating point calculations. Also the collision itself may not be resolved as a perfect point-to-point reflection, which means the ball might "slide," which will result in the angle of reflection changing.
However I would still expect to see more collisions then just one or two. Make sure the
restitution
of both objects is set to 1.0 and make sure the ball'slinear damping
is set to 0.affectedByGravity
should obviously be false.Friction
should be set to 0. You can try settingusesPreciseCollisionDetection
to true.If you need the behavior you described in you picture to last indefinitely, you will need to set the position and velocity manually.