If touching sprite, then bounce script I use to minimise computing power and maximise accuracy. In this, script it is not possible for the balls to go out of rectangle no matter what speed!! I also used this for my covid-19 simulator, in which it was more complicated but the same basic starting script. you also can use the arrow keys up and down!