0 Favourites

Pong issues

  • Hi,

    Last night i started to recreate the game pong, after seeing a tutorial series on youtube. All went quite well besides that im trying to figure out what causes the cpu paddle to start moving upwards every time the ball is destroyed. Im guessing that the program thinks the CPU paddle Y value is greater than the balls since that is the only code that moves the cpu paddle up. But how could this be as the ball is destroyed?

    Another thing is that i'd like to try to make an exact copy of the original pong, and i noticed that it releases the ball from the middle from that Y value where the ball went to the goal. How would i fix it so id get my pong to do this as well. Also, i now have it set so that it shoots the ball just randomly, how would i make it to shoot at the player who just lost?

    capx file as attachment.

  • As for why your paddle is traveling up, yes the program thinks the Y position of the ball is higher than the paddle. If there is no ball to get a position from, the value is always 0. You could solve this by adding a condition to the motion of the paddle that checks to see if at ball is in the layout. If one isn't, don't move the paddle.

    To get the ball to spawn at the same Y position where it left the board, just add a global variable and store the Y position when the ball is destroyed. Then use this value as the Y position when the ball is spawned.

  • Big thanks FargFAther, got it to work just great.Paddle stops and resets in the middle after a match, and I didn't even need to use global variables as i got the ball to spawn where i want it to by ordering the spawn point to move its Y position to the same as the ball where it got destroyed. Simple.

    However i dont really get it how can the spawnpoint know the correct Y position if the ball is allready destroyed? kinda strange even if it works. Any insight to this?

    Pretty much the last dilemma i have with this is how can i set it so that it randomly shoots the ball on both directions in start of the game. I have it set on random (180) degrees, but this has a few flaws, the bigger being that if the ball launches from 90 degrees, it will just keep bouncing between the ceiling, another would be that it only launces downwards when it would be better if it could launch also upwards. So i basically need a contained random launch for both directions somehow like "on start of layout-> ball> set bullet rotation random (-60,60 or 120,240). How would i do this correctly? Also the ball sometimes bounces at a very steep angle so it hakea forever to reach the other player, OR actually start to turn backwards Like a boomerang, very odd. Would be happy if someone coule enlighten me a bit with these.

  • Bump in the hope for an answer.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Hi ya,

    Please see provided attachment.

  • 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).

  • 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

  • Thanks for the replys! wonderful ideas. Got it to work just fine

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)