bernivic135 wrote:Hi. What you can do is that when the ball contacts with the object in the wall, the system creates a new instance of the ball and then sets the direction in a random number between 0 and 180 (if you set it that appears in the upper centre).
You dont even need a new instance. Just set the ball to stop, move to the center, turn in the new direction, and then start moving again.
If I were making a pong clone my solution to do it in as few events as possable would be to simply use the math expressions
A = Current angle the ball is moving Ball.angle
B = random(-60,60) <-this is absolute and not depended on the balls current angle ie 0deg is pointing right. depending on the min/max angel you want your ball to move
When the game starts or the Ball hits a paddle simply enter the new angle of movement as
there are four quadrants that a angel falls into, this equation will tell the ball to turn ether true left or right 0deg vs 180deg depending on which direction it was moving to begin with. Then pick a new angel between what range you wish the ball to move.
For hitting the wall just make change it to Ball.angle(Ball.angel-(Ball.angel+1)) which will bounce the ball in the same angle but reversed in positive or negative. A ball hitting the bottom wall at -30deg will then move at +30deg
There is probably a less mathy way tough events but I love my one step events.
And for starting a new round just have a boolen var for "YouScore"=True. If the ball scores a point for you leave it true and if true start the ball moveing to the right. And if the Ai scores turn it False and move it left. +/- any random angle, just instead of the expreshion Ball.angle just use 180 to move it to you or 0 to move it to the Ai. In just 3 or 4 events
ps you need two events for when the ball hits a wall and for when it hits a paddle
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland