Get Pong ball to bounce correctly off sides

Get help using Construct 2

Post » Tue Feb 14, 2012 9:44 pm

Im a beginner here, trying to remake pong. I'm having trouble getting the "ball"(which is a square sprite unless someone can help me with that too) to bounch off the paddles correctly like the do in the game. Also to bounce correctly of the top and bottom walls, but get destroyed when the left/right walls. Right now it just crashes into the wall and stops
B
2
Posts: 5
Reputation: 410

Post » Wed Feb 15, 2012 12:29 am

Hey sbakht, welcome to the forums!

How are you making the ball move? The simplest way for something like this is to assign it the Bullet behavior. That behavior has a setting on the property bar on the left called "bounce off solids?", which if you set to yes will give you what you're looking for. All you have to do after that is assign the paddles and the top/bottom walls the Solid behavior. Leave the left/right walls without it so the ball won't bounce off of those.

Lemme know if you need more of an explanation, or an example file to show you what I mean.
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Wed Feb 15, 2012 2:01 am

Ya i had it as bullet with bounce off solids on. It will just bounce on a straight path back and forth if not set initially at an angle. If set at an angle. it follows the same path no matter how you hit it. It just seems to move differently in the real game depending on how fast you move the paddle and in what direction

For the walls, I just have a black picture as background. How would you set a specific side to solid. I could make some invisible block and make that solid...

I think an example might help.

http://dl.dropbox.com/u/17817406/Pong.capxsbakht2012-02-15 02:24:22
B
2
Posts: 5
Reputation: 410

Post » Wed Feb 15, 2012 3:45 am

Hello sbakht

Here is a pong game I made a while back:

Pong.capx

If your using the free version of C2 I don't know if you will be able to open it because I think I used 5 layers. If you cant just let me know, and I will try to mod it for you.

This is not the only way to make a pong game but it is the easiest way I could find to with C2.

I didn't comment the event sheet because I'm lazy, and it is pretty small. So if you have any questions about it just ask.

This pong game comes with a AI (Artificial Intelligence). You can adjust the AI speed to make it easier, or harder to play by looking for were it says "lerp(Paddle_AI.Y, Puck.Y,0.05)", and changing the speed "0.05" to a higher or lower number. You can also adjust the ball speed, and acceleration in the layout properties window.

Just look through the events sheet to see how you can set the ball to start at random angles to give your game a more real feel.

I hope this helps.
Wink2012-02-15 03:47:28
B
50
S
11
G
8
Posts: 479
Reputation: 9,911

Post » Wed Feb 15, 2012 11:03 am

Hello,

have you tried to change the collision-polygon of the paddle, in this version it is just a box... give it some angels or cut the corners, than you get more control over the ball.

Look here for an example

Enjoy coding...

StefanKuschelbauch2012-02-15 11:05:01
B
5
S
1
G
3
Posts: 46
Reputation: 1,581

Post » Wed Feb 15, 2012 11:15 pm

Thanks all, got it working.
B
2
Posts: 5
Reputation: 410


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], HugeCube, imnotspecial, tomi71, totoe and 20 guests